Class: DashcodeConverter::Nib::Nib
- Inherits:
-
Object
- Object
- DashcodeConverter::Nib::Nib
- Defined in:
- lib/dashcode-converter/nib.rb
Constant Summary collapse
- DECL_TEMPLATE =
<<-EOF /*jsl:import coherent*/ NIB('<%=name%>', { <%=items_array.join(",\n\n").indent(INDENT)%>, <%=_owner_decl.indent(INDENT)%> }); EOF
Instance Attribute Summary collapse
-
#items ⇒ Object
readonly
Returns the value of attribute items.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#owner ⇒ Object
readonly
Returns the value of attribute owner.
-
#views ⇒ Object
readonly
Returns the value of attribute views.
Instance Method Summary collapse
- #_owner_decl ⇒ Object
- #add_datasources_from_path(path) ⇒ Object
- #add_item(item) ⇒ Object
- #add_owner_reference(name, reference) ⇒ Object
- #add_view(view) ⇒ Object
- #add_view_from_path(path, name = @name) ⇒ Object
- #declaration ⇒ Object
-
#initialize(name, owner) ⇒ Nib
constructor
A new instance of Nib.
- #parse_parts(path) ⇒ Object
- #unique_name(basename) ⇒ Object
Constructor Details
#initialize(name, owner) ⇒ Nib
Returns a new instance of Nib.
26 27 28 29 30 31 32 33 |
# File 'lib/dashcode-converter/nib.rb', line 26 def initialize(name, owner) @name= name @owner= owner @owner_references= {} @items= {} @views= [] add_owner_reference('view', name) end |
Instance Attribute Details
#items ⇒ Object (readonly)
Returns the value of attribute items.
24 25 26 |
# File 'lib/dashcode-converter/nib.rb', line 24 def items @items end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/dashcode-converter/nib.rb', line 24 def name @name end |
#owner ⇒ Object (readonly)
Returns the value of attribute owner.
24 25 26 |
# File 'lib/dashcode-converter/nib.rb', line 24 def owner @owner end |
#views ⇒ Object (readonly)
Returns the value of attribute views.
24 25 26 |
# File 'lib/dashcode-converter/nib.rb', line 24 def views @views end |
Instance Method Details
#_owner_decl ⇒ Object
98 99 100 |
# File 'lib/dashcode-converter/nib.rb', line 98 def _owner_decl "owner: #{@owner_references.to_json(JSON_PARAMS)}" end |
#add_datasources_from_path(path) ⇒ Object
50 51 52 53 54 55 56 57 58 |
# File 'lib/dashcode-converter/nib.rb', line 50 def add_datasources_from_path(path) datasources= parse_parts(path) datasources.each { |name, spec| datasource= NibItem.new(name, self) datasource.parse_spec(spec) items[name]= datasource add_owner_reference(name, name) } end |
#add_item(item) ⇒ Object
40 41 42 |
# File 'lib/dashcode-converter/nib.rb', line 40 def add_item(item) items[item.name]= item end |
#add_owner_reference(name, reference) ⇒ Object
60 61 62 |
# File 'lib/dashcode-converter/nib.rb', line 60 def add_owner_reference(name, reference) @owner_references[name]= JavascriptCode("REF('#{reference}')") end |
#add_view(view) ⇒ Object
35 36 37 38 |
# File 'lib/dashcode-converter/nib.rb', line 35 def add_view(view) items[view.name]= view views << view end |
#add_view_from_path(path, name = @name) ⇒ Object
44 45 46 47 48 |
# File 'lib/dashcode-converter/nib.rb', line 44 def add_view_from_path(path, name=@name) view= View.new(name, self) view.parse_spec(parse_parts(path)) add_view(view) end |
#declaration ⇒ Object
64 65 66 67 68 69 70 |
# File 'lib/dashcode-converter/nib.rb', line 64 def declaration return @declaration if @declaration items_array= items.map { |key, value| value.declaration } @declaration= ERB.new(DECL_TEMPLATE.remove_indent).result binding end |
#parse_parts(path) ⇒ Object
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/dashcode-converter/nib.rb', line 72 def parse_parts(path) in_json= false json= "{\n" text= File.read(path) text.each { |line| if in_json json << line next end next unless (line =~ /dashcodePartSpecs/ || line =~ /dashcodeDataSources/) in_json= true } JSON.parse(json.gsub(/;$/,'')) end |
#unique_name(basename) ⇒ Object
88 89 90 91 92 93 94 95 96 |
# File 'lib/dashcode-converter/nib.rb', line 88 def unique_name(basename) index=0 name= basename while items.include?(name) index+=1 name= "#{basename}#{index}" end name end |