Class: Nitro::SelectedIfMorpher

Inherits:
StandardMorpher show all
Defined in:
lib/nitro/compiler/morphing.rb

Overview

attribute: selected_if, checked_if, selected_unless, checked_unless

<option value=“1” selected_if=“@cond”>opt1</option>

becomes

<?r if @cond ?>

<option value="1" selected="selected">opt1</option>

<?r else ?>

<option value="1">opt1</option>

<?r end ?>

Instance Method Summary collapse

Methods inherited from StandardMorpher

#after_end

Methods inherited from Morpher

#after_end, #initialize

Constructor Details

This class inherits a constructor from Nitro::Morpher

Instance Method Details

#after_start(buffer) ⇒ Object



123
124
125
# File 'lib/nitro/compiler/morphing.rb', line 123

def after_start(buffer)
  @start_index = buffer.length
end

#before_end(buffer) ⇒ Object



127
128
129
130
131
132
133
134
# File 'lib/nitro/compiler/morphing.rb', line 127

def before_end(buffer)
  @attributes.delete(@attr)
  @end_index = buffer.length
  buffer << Morphing.emit_end(@name)
  buffer << "<?r else ?>"
  buffer << Morphing.emit_start(@name, @attributes)
  buffer << buffer[@start_index...@end_index]
end

#before_start(buffer) ⇒ Object



116
117
118
119
120
121
# File 'lib/nitro/compiler/morphing.rb', line 116

def before_start(buffer)
  @attr, @cond = @key.split('_')
  @attributes.delete(@key)
  @attributes[@attr] = @attr
  buffer << "<?r #@cond #@value ?> "
end