Sha256: c642c2247b3bca3d200e022f20a1867f895fc0850235a2ca4b5c052b761791cb

Contents?: true

Size: 974 Bytes

Versions: 5

Compression:

Stored size: 974 Bytes

Contents

module Flutterby
  class View
    attr_reader :node
    alias_method :page, :node

    def initialize(node)
      @node = node
    end

    def date_format(date, fmt)
      date.strftime(fmt)
    end

    def render(expr, *args)
      find(expr).render(*args)
    end

    def find(*args)
      node.find(*args) or raise "No node found for #{args}"
    end

    def siblings(*args)
      node.siblings(*args)
    end

    class << self
      def for(file)
        # create a new view instance
        view = new(file)

        # walk the tree up to dynamically extend the view
        file.walk_down do |e|
          if view_node = e.sibling("_view.rb")
            case view_node.ext
            when "rb" then
              view.instance_eval(view_node.source)
            else
              raise "Unknown view extension #{view_node.full_name}"
            end
          end
        end

        # return the finished view object
        view
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
flutterby-0.1.0 lib/flutterby/view.rb
flutterby-0.0.25 lib/flutterby/view.rb
flutterby-0.0.24 lib/flutterby/view.rb
flutterby-0.0.23 lib/flutterby/view.rb
flutterby-0.0.22 lib/flutterby/view.rb