Class: RideTheStreetcar::DSL

Inherits:
Object
  • Object
show all
Includes:
StatementsList, Streamlined::Renderable
Defined in:
lib/ride_the_streetcar/dsl.rb

Instance Method Summary collapse

Methods included from StatementsList

#[], #apply, #console, #custom, #js, #navigate, #query_selector, #query_selector_all, #set_property

Instance Method Details

#ride(start_transition: false) {|| ... } ⇒ String

Write your Streetcar logic within a block using the DSL

Parameters:

  • start_transition (Boolean) (defaults to: false)

Yield Parameters:

Returns:

  • (String)

    serialized statements HTML output



15
16
17
18
19
20
# File 'lib/ride_the_streetcar/dsl.rb', line 15

def ride(start_transition: false, &block)
  @start_transition = start_transition
  block.arity == 1 ? yield(self) : instance_exec(&block)

  template.to_s.strip.tap { @statements.clear }
end

#statementsObject



8
# File 'lib/ride_the_streetcar/dsl.rb', line 8

def statements = @statements ||= []

#templateObject

rubocop:disable Style/IfUnlessModifier



23
24
25
26
27
28
# File 'lib/ride_the_streetcar/dsl.rb', line 23

def template
  html->{ <<~HTML
    <sc-line#{text -> { " start-transition" } if @start_transition}>#{html_map(statements) { |statement| render(statement) }}</sc-line>
  HTML
  }
end