Class: Blacksmith::Preprocessor

Inherits:
Object
  • Object
show all
Defined in:
lib/blacksmith/preprocessor.rb

Class Method Summary collapse

Class Method Details

.get_file(filename) ⇒ Object



6
7
8
# File 'lib/blacksmith/preprocessor.rb', line 6

def get_file(filename)
  File.open("#{Blacksmith.config.source_folder}/#{filename}.js")
end

.proccess(filename) ⇒ Object



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
# File 'lib/blacksmith/preprocessor.rb', line 11

def proccess(filename)
  file = get_file(filename)
  input_file = file.readlines
  output = input_file.map { |line|
    if line =~ /\/\/#/
      #line.gsub!(/\/\/#/, '').strip!
      case line
      when /include/
        included_filename = line.match(/include\s+(.*)/)[1].strip
        proccess(included_filename)
      when /insert/
        include_arg = line.match(/insert\s+(.*)/)[1].strip
        get_file(include_arg).read
      when /if_env/
        env = line.match(/if_env\s+(.*)/)[1].strip
        if Blacksmith.config.env == env
          line
        else
          ''
        end
      else
        line
      end
    else
      line
    end
  }.join()
end