Class: PSD::EngineData
- Inherits:
-
Object
- Object
- PSD::EngineData
- Includes:
- DocumentHelpers, Export
- Defined in:
- lib/psd/enginedata.rb,
lib/psd/enginedata/node.rb,
lib/psd/enginedata/text.rb,
lib/psd/enginedata/errors.rb,
lib/psd/enginedata/export.rb,
lib/psd/enginedata/version.rb,
lib/psd/enginedata/instruction.rb,
lib/psd/enginedata/exporters/css.rb,
lib/psd/enginedata/document_helpers.rb,
lib/psd/enginedata/instructions/noop.rb,
lib/psd/enginedata/instructions/number.rb,
lib/psd/enginedata/instructions/string.rb,
lib/psd/enginedata/instructions/boolean.rb,
lib/psd/enginedata/instructions/hash_end.rb,
lib/psd/enginedata/instructions/property.rb,
lib/psd/enginedata/instructions/hash_start.rb,
lib/psd/enginedata/instructions/single_line_array.rb,
lib/psd/enginedata/instructions/property_with_data.rb,
lib/psd/enginedata/instructions/number_with_decimal.rb,
lib/psd/enginedata/instructions/multi_line_array_end.rb,
lib/psd/enginedata/instructions/multi_line_array_start.rb
Overview
:nodoc:
Defined Under Namespace
Modules: DocumentHelpers, Export Classes: Instruction, Node, Text, TokenNotFound
Constant Summary collapse
- INSTRUCTIONS =
All of the instructions as defined by the EngineData spec.
[ Instruction::HashStart, Instruction::HashEnd, Instruction::SingleLineArray, Instruction::MultiLineArrayStart, Instruction::MultiLineArrayEnd, Instruction::Property, Instruction::PropertyWithData, Instruction::String, Instruction::NumberWithDecimal, Instruction::Number, Instruction::Boolean, Instruction::Noop ]
- VERSION =
"0.2.3"
Instance Attribute Summary collapse
-
#node ⇒ Object
(also: #result)
Returns the value of attribute node.
-
#node_stack ⇒ Object
Returns the value of attribute node_stack.
-
#property ⇒ Object
Returns the value of attribute property.
-
#property_stack ⇒ Object
Returns the value of attribute property_stack.
-
#text ⇒ Object
readonly
Returns the value of attribute text.
Class Method Summary collapse
-
.load(file) ⇒ Object
Read a file containing EngineData markup and initialize a new instance.
Instance Method Summary collapse
-
#initialize(text) ⇒ EngineData
constructor
Create a new Text instance and initialize our parsing stacks.
-
#parse! ⇒ Object
Parses the full document.
-
#parse_tokens(text) ⇒ Object
Go through each instruction until a token match is found, then parse the matches.
-
#parsed? ⇒ Boolean
Has the document been parsed yet?.
Methods included from Export::CSS
Methods included from DocumentHelpers
#reset_node, #set_node, #set_property, #stack_pop, #stack_push, #update_node
Constructor Details
#initialize(text) ⇒ EngineData
Create a new Text instance and initialize our parsing stacks.
45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/psd/enginedata.rb', line 45 def initialize(text) @text = Text.new(text) @property_stack = [] @node_stack = [] @property = :root @node = nil @parsed = false end |
Instance Attribute Details
#node ⇒ Object Also known as: result
Returns the value of attribute node.
17 18 19 |
# File 'lib/psd/enginedata.rb', line 17 def node @node end |
#node_stack ⇒ Object
Returns the value of attribute node_stack.
17 18 19 |
# File 'lib/psd/enginedata.rb', line 17 def node_stack @node_stack end |
#property ⇒ Object
Returns the value of attribute property.
17 18 19 |
# File 'lib/psd/enginedata.rb', line 17 def property @property end |
#property_stack ⇒ Object
Returns the value of attribute property_stack.
17 18 19 |
# File 'lib/psd/enginedata.rb', line 17 def property_stack @property_stack end |
#text ⇒ Object (readonly)
Returns the value of attribute text.
16 17 18 |
# File 'lib/psd/enginedata.rb', line 16 def text @text end |
Class Method Details
.load(file) ⇒ Object
Read a file containing EngineData markup and initialize a new instance.
40 41 42 |
# File 'lib/psd/enginedata.rb', line 40 def self.load(file) self.new File.read(file) end |
Instance Method Details
#parse! ⇒ Object
Parses the full document.
58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/psd/enginedata.rb', line 58 def parse! return if parsed? while true line = @text.current @parsed = true and return if line.nil? parse_tokens(line) @text.next! end end |
#parse_tokens(text) ⇒ Object
Go through each instruction until a token match is found, then parse the matches.
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'lib/psd/enginedata.rb', line 77 def parse_tokens(text) INSTRUCTIONS.each do |inst| match = inst.match(text) return inst.new(self, text).execute! if match end # This is a hack for the Japanese character rules that the format embeds match = Instruction::String.match(text + @text.next) if match text += @text.next! return Instruction::String.new(self, text).execute! end raise TokenNotFound.new("Text = #{text.dump}, Line = #{@text.line + 1}") end |
#parsed? ⇒ Boolean
Has the document been parsed yet?
71 72 73 |
# File 'lib/psd/enginedata.rb', line 71 def parsed? @parsed end |