Class: Raw::SelectedIfMorpher

Inherits:
StandardMorpher show all
Defined in:
lib/raw/compiler/filter/morph/selected_if.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 Attribute Summary

Attributes inherited from Morpher

#attributes, #key, #name, #value

Class Method Summary collapse

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 Raw::Morpher

Class Method Details

.keyObject



18
19
20
# File 'lib/raw/compiler/filter/morph/selected_if.rb', line 18

def self.key
  "selected_if"
end

Instance Method Details

#after_start(buffer) ⇒ Object



29
30
31
# File 'lib/raw/compiler/filter/morph/selected_if.rb', line 29

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

#before_end(buffer) ⇒ Object



33
34
35
36
37
38
39
40
# File 'lib/raw/compiler/filter/morph/selected_if.rb', line 33

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



22
23
24
25
26
27
# File 'lib/raw/compiler/filter/morph/selected_if.rb', line 22

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