Class: ExpressTemplates::Components::UnlessBlock
Instance Attribute Summary collapse
-
#conditional ⇒ Object
readonly
Returns the value of attribute conditional.
Attributes inherited from Expander
Instance Method Summary collapse
- #compile ⇒ Object
-
#initialize(*args) ⇒ UnlessBlock
constructor
A new instance of UnlessBlock.
Methods included from Capabilities::Parenting
Methods inherited from Base
Methods included from Capabilities::Iterating
Methods included from Capabilities::Wrapping
Methods included from Capabilities::Rendering
Methods included from Capabilities::Templating
Methods included from Macro
Methods inherited from Expander
#expand, #initialize_expander, #method_missing, #process_children!, register_macros_for
Constructor Details
#initialize(*args) ⇒ UnlessBlock
Returns a new instance of UnlessBlock.
7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/express_templates/components/unless_block.rb', line 7 def initialize(*args) @conditional = args.shift @alt = args.shift[:alt] if args.first.kind_of?(Hash) parent = args.shift if @conditional.kind_of?(Symbol) @conditional = @conditional.to_s elsif @conditional.kind_of?(Proc) @conditional = "(#{@conditional.source}.call)" elsif iterator.kind_of?(String) @conditional = "(#{@conditional}.call)" else raise "UnlessBlock unknown conditional: #{@conditional.inspect}" end if @alt.kind_of?(Proc) @alt = _compile_fragment @alt elsif @alt.nil? @alt = "''" end end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class ExpressTemplates::Expander
Instance Attribute Details
#conditional ⇒ Object (readonly)
Returns the value of attribute conditional.
5 6 7 |
# File 'lib/express_templates/components/unless_block.rb', line 5 def conditional @conditional end |
Instance Method Details
#compile ⇒ Object
28 29 30 31 32 33 34 35 36 |
# File 'lib/express_templates/components/unless_block.rb', line 28 def compile s = unless @alt %Q((unless #{@conditional}#{compile_children}\nend)) else %Q((unless #{@conditional}#{compile_children}\nelse #{@alt}\nend)) end puts s if ENV['DEBUG'].eql?('true') s end |