Class: Frontsau::StaticAssetsCompiler

Inherits:
Object
  • Object
show all
Defined in:
lib/frontsau/assets/static_assets_compiler.rb

Instance Method Summary collapse

Instance Method Details

#compile(file, type) ⇒ Object



35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/frontsau/assets/static_assets_compiler.rb', line 35

def compile file, type
  puts "  => #{file}"
  begin
    send "compile_#{type}", file
  rescue => e
    puts ""
    puts "    --------------------------------------------"
    puts "    ERROR: "+e.message
    puts "    --------------------------------------------"
    puts ""
  end
end

#compile_coffee(file) ⇒ Object



9
10
11
12
13
14
15
16
17
# File 'lib/frontsau/assets/static_assets_compiler.rb', line 9

def compile_coffee file
  filename = File.basename file,'.*'
  type = File.extname file
  path = File.dirname file
  input = File.read file
  output = "// FILE GENERATED FROM #{filename}.coffee\n\n"+CoffeeScript.compile(input)
  output_file = File.expand_path "#{filename}.js",path
  File.write output_file,output
end

#compile_haml(file) ⇒ Object



31
32
33
# File 'lib/frontsau/assets/static_assets_compiler.rb', line 31

def compile_haml file
  `php plugins/Room13Web/bin/haml-compiler.php #{file}`
end

#compile_sass(file) ⇒ Object



20
21
22
23
24
25
26
27
28
29
# File 'lib/frontsau/assets/static_assets_compiler.rb', line 20

def compile_sass file
  filename = File.basename file,'.*'
  type = File.extname file
  path = File.dirname file
  input = File.read file
  paths = Dir['plugins/*/static/css', 'vendor/bower/compass/core/stylesheets', 'vendor/bower']
  output = "/* FILE GENERATED FROM #{filename}.sass */\n\n"+Sass.compile(input, syntax: :sass, load_paths: paths)
  output_file = File.expand_path "#{filename}.css",path
  File.write output_file,output
end

#is_type(type, file) ⇒ Object



4
5
6
7
# File 'lib/frontsau/assets/static_assets_compiler.rb', line 4

def is_type type, file
  filetype = File.extname file
  filetype == ".#{type}"
end