Class: DashcodeConverter::Nib::View

Inherits:
Object
  • Object
show all
Defined in:
lib/dashcode-converter/nib/view.rb

Constant Summary collapse

DECL_TEMPLATE =
<<-EOF
    '<%=name%>': <%=is_template ? "VIEW_TEMPLATE" : "VIEW"%>({
    <%=views.join(",\n\n").indent(INDENT)%>
    })
EOF

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, nib) ⇒ View

Returns a new instance of View.



15
16
17
18
19
20
# File 'lib/dashcode-converter/nib/view.rb', line 15

def initialize(name, nib)
  @name= name
  @nib= nib
  @items= []
  @items_by_id= {}
end

Instance Attribute Details

#is_templateObject

Returns the value of attribute is_template.



13
14
15
# File 'lib/dashcode-converter/nib/view.rb', line 13

def is_template
  @is_template
end

#itemsObject (readonly)

Returns the value of attribute items.



12
13
14
# File 'lib/dashcode-converter/nib/view.rb', line 12

def items
  @items
end

#items_by_idObject (readonly)

Returns the value of attribute items_by_id.



12
13
14
# File 'lib/dashcode-converter/nib/view.rb', line 12

def items_by_id
  @items_by_id
end

#nameObject (readonly)

Returns the value of attribute name.



12
13
14
# File 'lib/dashcode-converter/nib/view.rb', line 12

def name
  @name
end

#nibObject (readonly)

Returns the value of attribute nib.



12
13
14
# File 'lib/dashcode-converter/nib/view.rb', line 12

def nib
  @nib
end

Instance Method Details

#add_item(item) ⇒ Object



27
28
29
30
31
# File 'lib/dashcode-converter/nib/view.rb', line 27

def add_item(item)
  item.view= self
  @items_by_id[item.name]= item
  @items << item
end

#declarationObject



41
42
43
44
45
46
# File 'lib/dashcode-converter/nib/view.rb', line 41

def declaration
  return @declaration if @declaration
  
  views= items.map { |item| item.declaration }
  @declaration= ERB.new(DECL_TEMPLATE.remove_indent).result binding
end

#parse_spec(spec) ⇒ Object



33
34
35
36
37
38
39
# File 'lib/dashcode-converter/nib/view.rb', line 33

def parse_spec(spec)
  spec.each { |id, part_spec|
    item= NibItem.new("##{id}", nib)
    item.parse_spec(part_spec)
    add_item(item)
  }
end

#remove_item(item) ⇒ Object



22
23
24
25
# File 'lib/dashcode-converter/nib/view.rb', line 22

def remove_item(item)
  @items_by_id.delete(item.name)
  @items.delete(item)
end