Sha256: fca5db2230dacf3b6e15a304d3a7a4ca0190ca4df425b81da0facdb08ad72c09

Contents?: true

Size: 1.23 KB

Versions: 6

Compression:

Stored size: 1.23 KB

Contents

class UnderOs::Page::Layout

  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

  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

  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

  def build_layout_from_nothing
    @page._.view = UIView.alloc.init
    @page._.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight
  end

  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

end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
under-os-ui-1.4.0 lib/under_os/page/layout.rb
under-os-1.3.0 lib/under_os/page/layout.rb
under-os-1.2.1 lib/under_os/page/layout.rb
under-os-1.2.0 lib/under_os/page/layout.rb
under-os-1.1.0 lib/under_os/page/layout.rb
under-os-1.0.0 lib/under_os/page/layout.rb