Class: JBundle::Compiler

Inherits:
Object
  • Object
show all
Defined in:
lib/jbundle/builder.rb

Constant Summary collapse

BUILDABLE_FILES =
['.js']

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, file_list, config) ⇒ Compiler

Returns a new instance of Compiler.



11
12
13
14
# File 'lib/jbundle/builder.rb', line 11

def initialize(name, file_list, config)
  @config, @file_list, @src_dir = config, file_list, config.src_dir
  @name, @dir = parse_name(name)
end

Instance Attribute Details

#dirObject (readonly)

Returns the value of attribute dir.



9
10
11
# File 'lib/jbundle/builder.rb', line 9

def dir
  @dir
end

#nameObject (readonly)

Returns the value of attribute name.



9
10
11
# File 'lib/jbundle/builder.rb', line 9

def name
  @name
end

#src_dirObject (readonly)

Returns the value of attribute src_dir.



9
10
11
# File 'lib/jbundle/builder.rb', line 9

def src_dir
  @src_dir
end

Instance Method Details

#buildable?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/jbundle/builder.rb', line 20

def buildable?
  BUILDABLE_FILES.include?(ext)
end

#extObject



16
17
18
# File 'lib/jbundle/builder.rb', line 16

def ext
  @ext ||= ::File.extname(name)
end

#filtered_licensesObject



37
38
39
# File 'lib/jbundle/builder.rb', line 37

def filtered_licenses
  @filtered_licenses ||= filter(licenses, :all)
end

#filtered_srcObject



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

def filtered_src
  @filtered_src ||= filter(raw_src, :all)
end

#licensesObject



52
53
54
55
56
57
58
# File 'lib/jbundle/builder.rb', line 52

def licenses
  @licenses ||= if @file_list.respond_to?(:licenses)
    read_files @file_list.licenses
  else
    ''
  end
end

#minObject



33
34
35
# File 'lib/jbundle/builder.rb', line 33

def min
  @min ||= filter(filtered_licenses, :min) + Closure::Compiler.new.compile(filter(filtered_src, :min))
end

#min_nameObject



45
46
47
48
49
50
# File 'lib/jbundle/builder.rb', line 45

def min_name
  @min_name ||= (
    ext = ::File.extname(name)
    name.sub(ext, '') + '.min' + ext
  )
end

#raw_srcObject



60
61
62
# File 'lib/jbundle/builder.rb', line 60

def raw_src
  @raw_src ||= read_files(@file_list)
end

#srcObject



29
30
31
# File 'lib/jbundle/builder.rb', line 29

def src
  @src ||= filter(filtered_licenses + filtered_src, :src)
end

#src_pathObject

This only makes sense for one-file objects



25
26
27
# File 'lib/jbundle/builder.rb', line 25

def src_path
  ::File.join(@src_dir, @file_list.original_name)
end