Class: Frozen::Template::Javascript

Inherits:
Base
  • Object
show all
Defined in:
lib/frozen/template/javascript.rb

Instance Attribute Summary collapse

Attributes inherited from Base

#file_path, #template_root_path

Instance Method Summary collapse

Methods inherited from Base

#build_file_path, #build_filename, #file_type, #relative_path, #relative_to_root, #render_to_file, #template_filename, #template_path

Constructor Details

#initialize(options = {}) ⇒ Javascript

Returns a new instance of Javascript.



11
12
13
14
15
16
17
# File 'lib/frozen/template/javascript.rb', line 11

def initialize(options={})
  @options = {
    :style => :compressed,
    :format => nil,
    :load_path => nil
  }.merge(options)
end

Instance Attribute Details

#file_load_pathObject

Returns the value of attribute file_load_path.



9
10
11
# File 'lib/frozen/template/javascript.rb', line 9

def file_load_path
  @file_load_path
end

#optionsObject

Returns the value of attribute options.



8
9
10
# File 'lib/frozen/template/javascript.rb', line 8

def options
  @options
end

Instance Method Details

#build_extensionObject



28
29
30
# File 'lib/frozen/template/javascript.rb', line 28

def build_extension
  ".js"
end

#build_pathObject



32
33
34
# File 'lib/frozen/template/javascript.rb', line 32

def build_path
  "js"
end

#contentsObject



24
25
26
# File 'lib/frozen/template/javascript.rb', line 24

def contents
  read_from_file(file_path)
end

#read_from_file(file) ⇒ Object



19
20
21
22
# File 'lib/frozen/template/javascript.rb', line 19

def read_from_file(file)
  self.file_load_path = File.dirname(file)
  super(file)
end

#renderObject



36
37
38
39
40
41
# File 'lib/frozen/template/javascript.rb', line 36

def render
  js = ""
  js = CoffeeScript.compile(contents) if file_type == "coffee"
  js = contents if file_type == "js"
  Uglifier.new.compile(js)
end