Class: DashcodeConverter::Nib::View

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

Constant Summary collapse

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, spec, nib) ⇒ View

Returns a new instance of View.



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

def initialize(name, spec, nib)
  @name= name
  @nib= nib
  @items= []
  @items_by_id= {}
  from_spec(spec) if spec
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



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

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

#from_spec(spec) ⇒ Object



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

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

#remove_item(item) ⇒ Object



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

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