Class: FabulatorFilter

Inherits:
TextFilter
  • Object
show all
Defined in:
lib/fabulator_filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.reset_pageObject



22
23
24
# File 'lib/fabulator_filter.rb', line 22

def self.reset_page
  @@page = nil
end

.set_page(p) ⇒ Object



18
19
20
# File 'lib/fabulator_filter.rb', line 18

def self.set_page(p)
  @@page = p
end

Instance Method Details

#filter(text) ⇒ Object



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/fabulator_filter.rb', line 2

def filter(text)
  ## we *really* need to know the current page we're working with
  begin
    ctx = ( @@page.fabulator_context rescue Fabulator::Expr::Context.new )
    text_parser = Fabulator::Template::Parser.new
    parsed = text_parser.parse(ctx, text)
    parsed.add_default_values(ctx.with_root(ctx.root.roots['data']))
    r = parsed.to_html({ :theme => FabulatorTags.theme_for_this_page || 'coal' })
    r.gsub!(/^\s*<\?xml\s+.*?\?>/, '')
Rails.logger.info("Filter produces: [#{r}]")
    r
  rescue => e
    "Unable to parse contents: #{e}"
  end
end