Class: UnderOs::Page::Layout
- Inherits:
-
Object
- Object
- UnderOs::Page::Layout
- Defined in:
- lib/under_os/page/layout.rb
Instance Method Summary collapse
- #build_layout_from_html ⇒ Object
- #build_layout_from_nothing ⇒ Object
- #build_layout_from_xib ⇒ Object
- #find_layout_with_type(ext) ⇒ Object
-
#initialize(page) ⇒ Layout
constructor
A new instance of Layout.
Constructor Details
#initialize(page) ⇒ Layout
Returns a new instance of Layout.
3 4 5 6 7 8 9 10 |
# File 'lib/under_os/page/layout.rb', line 3 def initialize(page) @page = page build_layout_from_xib || build_layout_from_html || build_layout_from_nothing @page.view = UnderOs::UI::View.new(@page._.view) @page.view.instance_variable_set('@_tag_name', 'PAGE') end |
Instance Method Details
#build_layout_from_html ⇒ Object
18 19 20 21 22 23 24 25 26 27 |
# File 'lib/under_os/page/layout.rb', line 18 def build_layout_from_html if filename = find_layout_with_type('html') if layout = UnderOs::Parser.parse(filename) if view = UnderOs::Page::Builder.views_from(layout)[0] @page._.view = view._ @page.title = layout[0][:attrs][:title] || '' end end end end |
#build_layout_from_nothing ⇒ Object
29 30 31 32 |
# File 'lib/under_os/page/layout.rb', line 29 def build_layout_from_nothing @page._.view = UIView.alloc.init @page._.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight end |
#build_layout_from_xib ⇒ Object
12 13 14 15 16 |
# File 'lib/under_os/page/layout.rb', line 12 def build_layout_from_xib if filename = find_layout_with_type('xib') @page._.view = NSBundle.mainBundle.loadNibNamed(filename.sub(/\.xib$/, ''), owner:self, options:nil)[0] end end |
#find_layout_with_type(ext) ⇒ Object
34 35 36 37 38 39 40 41 |
# File 'lib/under_os/page/layout.rb', line 34 def find_layout_with_type(ext) filename = @page.class.layout || "#{@page.name}.#{ext}" filename, type = filename.match(/^(.+?)\.([a-z]+)$/).to_a.slice(1,2) if type == ext && NSBundle.mainBundle.pathForResource(filename, ofType:type) "#{filename}.#{type}" end end |