File: slippers.rb

package info (click to toggle)
ruby-ramaze 2012.12.08-3
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,060 kB
  • ctags: 1,200
  • sloc: ruby: 10,446; makefile: 8
file content (51 lines) | stat: -rw-r--r-- 1,587 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
require 'slippers'

module Ramaze
  module View
    ##
    # View adapter for Slippers, see the website of Slippers for more
    # information: http://starapor.github.com/slippers/
    #
    #
    module Slippers
      def self.call(action, string)
        slippers = View.compile(string) do |s|
          ::Slippers::Engine.new(s, :template_group => template_group(action))
        end

        object_to_render = ::Slippers::BindingWrapper.new(action.instance.binding)
        html             = slippers.render(object_to_render)

        return html, 'text/html'
      end

      private

      def self.template_group(action)
        subtemplates = action.instance.ancestral_trait[:slippers_options] || {}
        missing_template_handler = action.instance.ancestral_trait[
          :slippers_missing_template_handler
        ]
        default_string = action.instance.ancestral_trait[
          :slippers_default_string
        ]

        views = action.instance.options[:views].map do |view|
          "#{action.instance.options[:roots]}/#{view}"
        end

        super_group = ::Slippers::TemplateGroup.new(
          :templates                => subtemplates,
          :missing_template_handler => missing_template_handler,
          :default_string           => default_string
        )

        ::Slippers::TemplateGroupDirectory.new(
          views, :super_group       => super_group,
          :missing_template_handler => missing_template_handler,
          :default_string           => default_string
        )
      end
    end # Slippers
  end # View
end # Ramaze