Sha256: e91befd8e83f446b7161f576d6bc864cc3cd20192d8ae1d463f4afd42d80254b

Contents?: true

Size: 1.05 KB

Versions: 13

Compression:

Stored size: 1.05 KB

Contents

module Temple
  module CoffeeScript
    module Filters
      class ControlFlow < Filter
        def on_if(condition, yes, no = nil)
          result = [:multi, [:code, "if #{condition}"], [:indent, compile(yes)]]
          while no && no.first == :if
            result << [:code, "else if #{no[1]}"] << [:indent, compile(no[2])]
            no = no[3]
          end
          result << [:code, 'else'] << [:indent, compile(no)] if no
          result
        end

        def on_case(arg, *cases)
          result = [:multi, [:code, arg ? "switch (#{arg})" : 'switch'], [:indent, [:multi]]]
          cases.map do |c|
            condition, *exps = c
            result[2][1] << [:code, condition == :else ? 'else' : "when #{condition}"]
            exps.each {|e| result[2][1] << [:indent, compile(e)] }
          end
          result
        end

        def on_cond(*cases)
          on_case(nil, *cases)
        end

        def on_block(code, exp)
          [:multi,
           [:code, code],
           [:indent, compile(exp)]]
        end
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
skim-0.11.0 lib/temple/coffee_script/filters/control_flow.rb
skim-0.10.0 lib/temple/coffee_script/filters/control_flow.rb
skim-0.9.3 lib/temple/coffee_script/filters/control_flow.rb
skim-0.9.2 lib/temple/coffee_script/filters/control_flow.rb
skim-0.9.1 lib/temple/coffee_script/filters/control_flow.rb
skim-0.9.0 lib/temple/coffee_script/filters/control_flow.rb
skim-0.8.6 lib/temple/coffee_script/filters/control_flow.rb
skim-0.8.5 lib/temple/coffee_script/filters/control_flow.rb
skim-0.8.4 lib/temple/coffee_script/filters/control_flow.rb
skim-0.8.3 lib/temple/coffee_script/filters/control_flow.rb
skim-0.8.2 lib/temple/coffee_script/filters/control_flow.rb
skim-0.8.1 lib/temple/coffee_script/filters/control_flow.rb
skim-0.8.0 lib/temple/coffee_script/filters/control_flow.rb