Sha256: cc26125a6f28c00ee932353164ca61158dc7ed2f8d8aa0727715b0cab52c04f0

Contents?: true

Size: 1019 Bytes

Versions: 16

Compression:

Stored size: 1019 Bytes

Contents

module RubySlippers
  module Engine
    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
        content = to_html page, @config
        type == :html ? to_html(:layout, @config, &Proc.new { content }) : send(:"to_#{type}", page)
      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

16 entries across 16 versions & 2 rubygems

Version Path
ruby_slippers-0.2.15 lib/ruby_slippers/context.rb
ruby_slippers-0.2.8 lib/ruby_slippers/context.rb
ruby_slippers-0.2.4 lib/ruby_slippers/context.rb
ruby_slippers-0.2.3 lib/ruby_slippers/context.rb
ruby_slippers-0.2.0 lib/ruby_slippers/context.rb
ruby-slippers-0.1.43 lib/ruby_slippers/context.rb
ruby-slippers-0.1.40 lib/ruby_slippers/context.rb
ruby-slippers-0.1.11 lib/ruby_slippers/context.rb
ruby-slippers-0.1.7 lib/ruby_slippers/context.rb
ruby-slippers-0.1.2 lib/ruby_slippers/context.rb
ruby-slippers-0.1.1 lib/ruby_slippers/context.rb
ruby-slippers-0.0.26 lib/ruby_slippers/context.rb
ruby-slippers-0.0.25 lib/ruby_slippers/context.rb
ruby-slippers-0.0.13 lib/ruby_slippers/context.rb
ruby-slippers-0.0.5 lib/ruby_slippers/context.rb
ruby-slippers-0.0.1 lib/ruby_slippers/context.rb