Class: Textigniter::Parsers::StyleParser

Inherits:
Object
  • Object
show all
Defined in:
lib/textigniter/parsers/style_parser.rb

Overview

The StyleParser parses css files. Currently it only parses less files.

Instance Method Summary collapse

Instance Method Details

#parse(content) ⇒ Object



37
38
39
40
41
42
43
44
45
46
# File 'lib/textigniter/parsers/style_parser.rb', line 37

def parse(content)
  # require less gem
  require 'less'
  # instantiate the parser
  parser = Less::Parser.new
  # parse the content
  tree = parser.parse(content)
  # return the output
  return tree.to_css
end

#process(build_list) ⇒ Object



4
5
6
7
8
9
10
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
# File 'lib/textigniter/parsers/style_parser.rb', line 4

def process(build_list)    
  # Output message
  STDOUT.puts "Rendering ".yellow_on_black + "[less]".blue_on_black + " styles ".yellow_on_black + "[OK]".green_on_black
  # create array to store processed items in
  items = Array.new
  # process the build list
  build_list.each do |f|
    # open the file for reading
    file = File.open(f, 'rb')
    # store the contents in contents and split it at --
    contents = file.read
    # create a hash to store info
    @h = Hash.new
    # get the directory
    directory = File.dirname(f).sub($twd,$owd) + '/'
    @h['directory'] = directory
    # get the file name
    @h['filename'] = File.basename(f, ".less")
    # filename for manifest
    @h['manifest'] = f
    # extension
    @h['extension'] = File.extname(f)
    # modified_at key
    @h['modified_at'] = File.mtime(f)
    # parse the content
    @h['output'] = parse(contents)
    # push processed item onto the array
    items.push @h
  end
  # return the items
  return items
end