Class: FrontCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/front_compiler/css_source/nested_styles.rb,
lib/front_compiler.rb,
lib/front_compiler/java_script/self_builder.rb,
lib/front_compiler/java_script/logic_compactor.rb,
lib/front_compiler/java_script/names_compactor.rb

Overview

This module contains the names compactor functionality

This module is a part of the JavaScript class and taken out just to keep the things simple

Copyright © 2008-2010 Nikolay Nemshilov

Defined Under Namespace

Classes: CssSource, HTMLCompactor, JavaScript, SourceCode

Constant Summary collapse

VERSION =
"1.1.0"

Instance Method Summary collapse

Constructor Details

#initializeFrontCompiler

Returns a new instance of FrontCompiler.



11
12
13
# File 'lib/front_compiler.rb', line 11

def initialize
  @html_compactor = HTMLCompactor.new
end

Instance Method Details

#compact_css(source) ⇒ Object

compacts a CSS source code



41
42
43
# File 'lib/front_compiler.rb', line 41

def compact_css(source)
  CssSource.new(source).compact
end

#compact_file(file) ⇒ Object

compacts the given file (path or a File object)



24
25
26
27
28
29
30
31
32
33
# File 'lib/front_compiler.rb', line 24

def compact_file(file)
  file = File.open(file, 'r') if file.is_a?(String)
  
  case file.path.split('.').last.downcase
    when 'js'   then compact_js   file.read
    when 'css'  then compact_css  file.read
    when 'html' then compact_html file.read
    else                          file.read
  end
end

#compact_files(list) ⇒ Object

compacts all the files out of the list and returns them as a single string



17
18
19
20
21
# File 'lib/front_compiler.rb', line 17

def compact_files(list)
  list.collect do |file|
    compact_file file
  end.join("\n")
end

#compact_html(source) ⇒ Object

compacts a HTML code



46
47
48
# File 'lib/front_compiler.rb', line 46

def compact_html(source)
  @html_compactor.minimize(source)
end

#compact_js(source) ⇒ Object

compacts a JavaScript source code



36
37
38
# File 'lib/front_compiler.rb', line 36

def compact_js(source)
  JavaScript.new(source).compact
end

#inline_css(source) ⇒ Object

inlines the css-sourcecode in a javascript code



51
52
53
# File 'lib/front_compiler.rb', line 51

def inline_css(source)
  CssSource.new(source).to_javascript
end