Module: Sinatra::RactiveHelpers

Defined in:
lib/fanforce/app_factory/config/helpers/ractive.rb

Instance Method Summary collapse

Instance Method Details

#column(size, &block) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
# File 'lib/fanforce/app_factory/config/helpers/ractive.rb', line 44

def column(size, &block)
  begin require 'haml' rescue LoadError raise 'You must have the haml gem installed to use Fanforce.compile_jquery_templates.' end
  if block
    context = Object.new
    class << context
      include Haml::Helpers
    end
    context.init_haml_helpers
    html = context.capture_haml(&block)
  end
  "<div class='small-12 medium-#{size} column'>\n#{html}</div>"
end

#compile_ractive_templates(options = {}, &block) ⇒ Object

Creates a string representation of a javascript object for ractive.js



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/fanforce/app_factory/config/helpers/ractive.rb', line 4

def compile_ractive_templates(options={}, &block)
  context = Object.new
  class << context
    include Haml::Helpers
  end
  context.init_haml_helpers

  format = options[:format] == 'html' ? :html : :json

  return context.capture_haml(&block) if format == :html
  single_line_html = context.capture_haml(&block).split(/\r?\n/).inject('') {|sl, l| sl += l.strip + ' ' }
  matches = single_line_html.scan(/<script id=[\"'](.*?)[\"'](?:.*?)>(.*?)(?:<\/script>)/mi)

  matches.inject({}) {|t,m| t[m[0]] = m[1]; t }.to_json
end

#ELSE_IF(helper, &block) ⇒ Object



36
37
38
# File 'lib/fanforce/app_factory/config/helpers/ractive.rb', line 36

def ELSE_IF(helper, &block)
  RACTIVE(helper, &block)
end

#FOREACH(helper, &block) ⇒ Object



40
41
42
# File 'lib/fanforce/app_factory/config/helpers/ractive.rb', line 40

def FOREACH(helper, &block)
  RACTIVE(helper, &block)
end

#IF(helper, &block) ⇒ Object



32
33
34
# File 'lib/fanforce/app_factory/config/helpers/ractive.rb', line 32

def IF(helper, &block)
  RACTIVE(helper, &block)
end

#RACTIVE(helper, &block) ⇒ Object

Raises:

  • (ArgumentError)


20
21
22
23
24
25
26
27
28
29
30
# File 'lib/fanforce/app_factory/config/helpers/ractive.rb', line 20

def RACTIVE(helper, &block)
  begin require 'haml' rescue LoadError raise 'You must have the haml gem installed to use Fanforce.compile_jquery_templates.' end
  raise ArgumentError, "Missing block" unless block_given?
  context = Object.new
  class << context
    include Haml::Helpers
  end
  context.init_haml_helpers
  helper = '#'+helper if helper !~ /^[#\^]/
  "{{#{helper}}}\n" + context.capture_haml(&block) + "{{/#{helper.gsub(/(#|\^)/,'')}}}"
end