Class: Jscompiler::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/jscompiler/config.rb

Class Method Summary collapse

Class Method Details

.compiler(group = nil) ⇒ Object



58
59
60
61
# File 'lib/jscompiler/config.rb', line 58

def self.compiler(group = nil)
  return config["compiler"] if group.nil?
  groups[group]["compiler"] || config["compiler"]
end

.compiler_command(group = nil, opts = {}) ⇒ Object



63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/jscompiler/config.rb', line 63

def self.compiler_command(group=nil, opts = {})
  cmplr = opts[:compiler] || compiler(group)["name"]

  case cmplr
  when 'closure'
    Jscompiler::Commands::Closure
  when 'yahoo'
    Jscompiler::Commands::Yahoo
  when 'uglifier'
    Jscompiler::Commands::Uglifier
  else
    raise("Unsupported compiler")
  end
end

.configObject

Configuration Attributes



40
41
42
# File 'lib/jscompiler/config.rb', line 40

def self.config
  @config ||= YAML::load(File.open(path)) 
end

.configured?Boolean

Returns:

  • (Boolean)


50
51
52
# File 'lib/jscompiler/config.rb', line 50

def self.configured?
  File.exists?(path)
end

.debug?(group) ⇒ Boolean

Returns:

  • (Boolean)


94
95
96
# File 'lib/jscompiler/config.rb', line 94

def self.debug?(group)
  output(group)["debug"]
end

.files(group) ⇒ Object



82
83
84
# File 'lib/jscompiler/config.rb', line 82

def self.files(group)
  groups[group]["files"]
end

.groupsObject



54
55
56
# File 'lib/jscompiler/config.rb', line 54

def self.groups
  config["groups"]
end

.output(group) ⇒ Object



86
87
88
# File 'lib/jscompiler/config.rb', line 86

def self.output(group)
  groups[group]["output"]
end

.output_destination(group, opts = {}) ⇒ Object



98
99
100
101
102
103
104
105
106
107
108
109
# File 'lib/jscompiler/config.rb', line 98

def self.output_destination(group, opts = {})
  path = output_path(group)
  parts = path.split("/")
  file_name = parts.pop
  if opts[:suffix]
    file_name = file_name.index('.js') ? file_name.gsub(".js", "#{opts[:suffix]}.js") : "#{file_name}#{opts[:suffix]}"
  end
  if opts[:prefix]
    file_name = "#{opts[:prefix]}#{file_name}"
  end
  "#{parts.join("/")}/#{file_name}"
end

.output_path(group) ⇒ Object



90
91
92
# File 'lib/jscompiler/config.rb', line 90

def self.output_path(group)
  output(group)["path"]
end

.pathObject



32
33
34
# File 'lib/jscompiler/config.rb', line 32

def self.path
  '.jscompiler'
end

.source_rootObject



78
79
80
# File 'lib/jscompiler/config.rb', line 78

def self.source_root
  config["source_root"]
end

.update_configObject



44
45
46
47
48
# File 'lib/jscompiler/config.rb', line 44

def self.update_config
  File.open(path, 'w') do |file| 
    file.write(config.to_yaml)
  end
end