Class: Slight::Engine

Inherits:
Object
  • Object
show all
Defined in:
lib/slight/engine.rb

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Engine

Returns a new instance of Engine.



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/slight/engine.rb', line 6

def initialize(options = {})
  @options = options
  Configuration.new(@options) do |c|
    c.shortcut :A, :css, "style"
    c.shortcut :A, :ln, "href"
    c.shortcut :A, :url, "href"
    c.shortcut :A, :char, "charset"
    c.shortcut :A, :fn, "src"
    c.shortcut :A, :lang, "language"
    c.shortcut :A, :xn, "xmlns"
    c.shortcut :A, :mf, "manifest"
    c.shortcut :T, "_", "div"
    #c.shortcut :T, "js", %q[script language="javascript"]
   #c.use PrettyHtmlOutput, :after if c.get(:pretty_html)
  end
  @template = Template.new(@options)
end

Instance Method Details

#render(src_file, src_data = nil, local_vars = {}) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/slight/engine.rb', line 24

def render(src_file, src_data = nil, local_vars={})
  # src file name is mainly using for identify issues for debugging
  # if data not given then read data from src file

  # Data > File

  #src_data = script.call if block_given?
  src_data ||= File.new(src_file).read
  
  @options[:before_filter].each do |f|
    src_data = f.do(src_data)
  end
 
  src_data = @template.render(src_data, src_file, local_vars)

  @options[:after_filter].each do |f|
    src_data = f.do(src_data)
  end
  src_data
end