Class: Alml::Engine::Line
- Inherits:
-
Object
- Object
- Alml::Engine::Line
- Defined in:
- lib/alml_engine.rb
Constant Summary collapse
- SPACES_PER_TAB =
How many spaces equals a single tab. The simpler the syntax, the faster the compiler.
2
- DIV_CLASS =
Designates a
<div>
element with the given class. ?.
- DIV_ID =
Designates a
<div>
element with the given id. ?#
- COMMENT =
Designates an XHTML/XML comment.
?!
- SCRIPT =
Designates script, the result of which is output.
?@
Instance Attribute Summary collapse
-
#command ⇒ Object
readonly
Returns the value of attribute command.
-
#full ⇒ Object
readonly
Returns the value of attribute full.
-
#line_number ⇒ Object
readonly
Returns the value of attribute line_number.
-
#open_output ⇒ Object
readonly
Returns the value of attribute open_output.
Class Method Summary collapse
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(line_text, line_number, previous_line) ⇒ Line
constructor
A new instance of Line.
- #parameter ⇒ Object
-
#render(previous_line, script_index, &block) ⇒ Object
Optinal block incase it’s dynamic The fact that there is only 1 self-closing tag makes it VERY easy to work with.
- #script? ⇒ Boolean
- #tabs ⇒ Object
Constructor Details
#initialize(line_text, line_number, previous_line) ⇒ Line
Returns a new instance of Line.
118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/alml_engine.rb', line 118 def initialize(line_text, line_number, previous_line) @full = line_text @line_number = line_number @command = line_text.strip return if empty? # Quit while we're ahead if !valid_compared_to_previous?(previous_line) raise SyntaxError.new("Line #{line_number}: The line was indented #{tab_distance_from(previous_line)} levels deeper than the previous line.") end # Up-front all the burden, except for dynamic content prerender_static_content end |
Instance Attribute Details
#command ⇒ Object (readonly)
Returns the value of attribute command.
109 110 111 |
# File 'lib/alml_engine.rb', line 109 def command @command end |
#full ⇒ Object (readonly)
Returns the value of attribute full.
109 110 111 |
# File 'lib/alml_engine.rb', line 109 def full @full end |
#line_number ⇒ Object (readonly)
Returns the value of attribute line_number.
109 110 111 |
# File 'lib/alml_engine.rb', line 109 def line_number @line_number end |
#open_output ⇒ Object (readonly)
Returns the value of attribute open_output.
109 110 111 |
# File 'lib/alml_engine.rb', line 109 def open_output @open_output end |
Class Method Details
.render_remaining_closures(previous_line) ⇒ Object
112 113 114 115 116 |
# File 'lib/alml_engine.rb', line 112 def self.render_remaining_closures(previous_line) buffer = '' previous_line.tabs.times { buffer << close_div } buffer end |
Instance Method Details
#empty? ⇒ Boolean
133 134 135 |
# File 'lib/alml_engine.rb', line 133 def empty? @command.nil? || @command.empty? end |
#parameter ⇒ Object
169 170 171 |
# File 'lib/alml_engine.rb', line 169 def parameter command[1..-1] end |
#render(previous_line, script_index, &block) ⇒ Object
Optinal block incase it’s dynamic The fact that there is only 1 self-closing tag makes it VERY easy to work with.
Any differences in tab distance can be attributed to a close div tag, and no other kinds of tags.
144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/alml_engine.rb', line 144 def render(previous_line, script_index, &block) return '' if empty? # Quit while we're ahead buffer = '' tab_distance = tab_distance_from(previous_line) if tab_distance < 0 (tab_distance * -1).times { buffer << render_close_div } elsif tab_distance == 0 && !previous_line.nil? && previous_line.requires_closing? buffer << render_close_div # same level divs end if script? buffer << render_script(command, script_index[0], &block) script_index[0] += 1 else buffer << @open_output end buffer end |
#script? ⇒ Boolean
137 138 139 |
# File 'lib/alml_engine.rb', line 137 def script? command[0] == SCRIPT end |
#tabs ⇒ Object
164 165 166 167 |
# File 'lib/alml_engine.rb', line 164 def tabs return @tabs unless @tabs.nil? @tabs = empty? ? 0 : @full[/^ */].length / SPACES_PER_TAB end |