Module: Ice::Handlers::Coffeekup

Defined in:
lib/ice/handlers/coffeekup/handler.rb

Class Method Summary collapse

Class Method Details

.call(template) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'lib/ice/handlers/coffeekup/handler.rb', line 22

def self.call(template)
  <<-COFFEEKUP
    template_source = <<-COFFEEKUP_TEMPLATE
      #{template.source}
    COFFEEKUP_TEMPLATE
    #{Base.variables}

    Ice::Handlers::Coffeekup.convert_template(template_source, variables.merge(local_assigns))
  COFFEEKUP
end

.convert_template(template_text, vars = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
# File 'lib/ice/handlers/coffeekup/handler.rb', line 7

def self.convert_template(template_text, vars = {})
  Base.convert_template(template_text) do |context|
    coffeescript_file = "#{File.dirname(__FILE__)}/../../../../js/coffee-script.js"
    coffeekup_file = "#{File.dirname(__FILE__)}/../../../../js/coffeekup.js"

    context.eval(open(coffeescript_file).read)
    context.eval(open(coffeekup_file).read)

    coffeekup_helpers_file = "#{File.dirname(__FILE__)}/../../../../js/lib/coffeekup-path-helper.coffee"
    combo = open(coffeekup_helpers_file).read + "\n" + template_text.sub(/^(\s)*/, "")
    template = context["coffeekup"]["compile"].call(combo)
    template.call({context: vars.to_ice})
  end
end