Sha256: 02a2de9a1c52872db5f70f5343af7c2104212a472bc634cf1592b230a798b239

Contents?: true

Size: 1.03 KB

Versions: 4

Compression:

Stored size: 1.03 KB

Contents

module Allegro

  class Site

    class Context
      include Template
      attr_reader :env

      def initialize ctx = {}, config = {}, path = "/", env = {}
        @config, @context, @path, @env = config, ctx, path, env
        @articles = Site.articles(@config[:ext]).reverse.map do |a|
          Article.new(a, @config)
        end

        ctx.each do |k, v|
          meta_def(k) { ctx.instance_of?(Hash) ? v : ctx.send(k) }
        end
      end

      def title
        @config[:title]
      end

      def render page, type
        if type == :html
          content = to_html page, @config
          to_html(:layout, @config, &Proc.new { content })
        else
          send(:"to_#{type}", page)
        end
      end

      def to_xml page
        xml = Builder::XmlMarkup.new(:indent => 2)
        instance_eval File.read("#{Paths[:templates]}/#{page}.builder")
      end
      alias :to_atom to_xml

      def method_missing m, *args, &blk
        @context.respond_to?(m) ? @context.send(m, *args, &blk) : super
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
allegro-0.0.0pre3 lib/allegro/context.rb
allegro-0.0.0pre2 lib/allegro/context.rb
allegro-0.0.0pre1 lib/allegro/context.rb
allegro-0.0.0pre lib/allegro/context.rb