Class: Massimo::Config
- Inherits:
-
OpenStruct
- Object
- OpenStruct
- Massimo::Config
- Defined in:
- lib/massimo/config.rb
Constant Summary collapse
- DEFAULT_OPTIONS =
{ :config_path => 'config.rb', :source_path => '.', :output_path => 'public', :environment => 'development', :resources_path => '.', :base_url => '/', :resources_url => '/', :javascripts_url => '/javascripts', :stylesheets_url => '/stylesheets' }.freeze
- JS_COMPRESSORS =
{ :jsmin => Crush::JSMin, :packr => Crush::Packr, :yui => Crush::YUI::JavaScriptCompressor, :closure => Crush::Closure::Compiler, :uglifier => Crush::Uglifier }
- CSS_COMPRESSORS =
{ :cssmin => Crush::CSSMin, :rainpress => Crush::Rainpress, :yui => Crush::YUI::CssCompressor, :sass => Crush::Sass::Engine }
Instance Method Summary collapse
-
#compress=(compress) ⇒ Object
Sets up Massimo to compress both JavaScript and CSS files.
-
#compress_css=(compress) ⇒ Object
Sets up Massimo to compress CSS files.
-
#compress_js=(compress) ⇒ Object
Sets up Massimo to compress JavaScript files.
-
#config_path ⇒ Object
The full, expanded path to the config file.
-
#css_compressor=(compressor) ⇒ Object
Sets the CSS compressor to use.
-
#css_compressor_options=(options) ⇒ Object
Sets the options used by the CSS compressor.
-
#environment ⇒ Object
Return the enviornment option wrapped by a StringInquirer, so you can query the environment like this: ‘config.environment.production?`.
-
#files_in(resource_name, extension = '*') ⇒ Object
Get an array of all the file paths found in the given resource name’s path, restricted to the given extension.
-
#initialize(options = nil) ⇒ Config
constructor
Creates a new configuration.
-
#js_compressor=(compressor) ⇒ Object
Sets the JavaScript compressor to use.
-
#js_compressor_options=(options) ⇒ Object
Sets the options used by the JavaScript compressor.
-
#options_for(lib_name) ⇒ Object
Convience method for getting options for a given library name.
-
#output_path ⇒ Object
The full, expanded path to the output directory.
-
#path_for(resource_name) ⇒ Object
Get a full, expanded path for the given resource name.
-
#source_path ⇒ Object
The full, expanded path to the source directory.
-
#url_for(resource_name) ⇒ Object
Get the configured URL for th given resource name.
Constructor Details
#initialize(options = nil) ⇒ Config
Creates a new configuration. Takes either a hash of options or a file path to a .yaml file.
39 40 41 42 43 |
# File 'lib/massimo/config.rb', line 39 def initialize( = nil) hash = DEFAULT_OPTIONS.dup hash.merge!(.symbolize_keys) if .is_a? Hash super hash end |
Instance Method Details
#compress=(compress) ⇒ Object
Sets up Massimo to compress both JavaScript and CSS files.
69 70 71 |
# File 'lib/massimo/config.rb', line 69 def compress=(compress) Crush.register if compress end |
#compress_css=(compress) ⇒ Object
Sets up Massimo to compress CSS files. By default, whichever CSS compression library is available, is used. To set the one you want to use see #css_compressor=.
106 107 108 |
# File 'lib/massimo/config.rb', line 106 def compress_css=(compress) Crush.register_css if compress end |
#compress_js=(compress) ⇒ Object
Sets up Massimo to compress JavaScript files. By default, whichever JavaScript compression library is available, is used. To set the one you want to use see #js_compressor=.
78 79 80 |
# File 'lib/massimo/config.rb', line 78 def compress_js=(compress) Crush.register_js if compress end |
#config_path ⇒ Object
The full, expanded path to the config file
46 47 48 |
# File 'lib/massimo/config.rb', line 46 def config_path File. super end |
#css_compressor=(compressor) ⇒ Object
Sets the CSS compressor to use. The compressor can be either a symbol mapping to the recognized Crush::Engines (see CSS_COMPRESSORS) or any Tilt::Template.
115 116 117 118 119 120 |
# File 'lib/massimo/config.rb', line 115 def css_compressor=(compressor) if compressor.respond_to?(:to_sym) compressor = CSS_COMPRESSORS[compressor.to_sym] end Tilt.prefer compressor, 'css' end |
#css_compressor_options=(options) ⇒ Object
Sets the options used by the CSS compressor.
125 126 127 |
# File 'lib/massimo/config.rb', line 125 def () self. = end |
#environment ⇒ Object
Return the enviornment option wrapped by a StringInquirer, so you can query the environment like this: ‘config.environment.production?`
62 63 64 |
# File 'lib/massimo/config.rb', line 62 def environment ActiveSupport::StringInquirer.new(super) end |
#files_in(resource_name, extension = '*') ⇒ Object
Get an array of all the file paths found in the given resource name’s path, restricted to the given extension.
146 147 148 |
# File 'lib/massimo/config.rb', line 146 def files_in(resource_name, extension = '*') Dir.glob File.join(path_for(resource_name), "**/*.#{extension}") end |
#js_compressor=(compressor) ⇒ Object
Sets the JavaScript compressor to use. The compressor can be either a symbol mapping to the recognized Crush::Engines (see JS_COMPRESSORS) or any Tilt::Template.
87 88 89 90 91 92 |
# File 'lib/massimo/config.rb', line 87 def js_compressor=(compressor) if compressor.respond_to?(:to_sym) compressor = JS_COMPRESSORS[compressor.to_sym] end Tilt.prefer compressor, 'js' end |
#js_compressor_options=(options) ⇒ Object
Sets the options used by the JavaScript compressor.
97 98 99 |
# File 'lib/massimo/config.rb', line 97 def () self. = end |
#options_for(lib_name) ⇒ Object
Convience method for getting options for a given library name. For instance, this is how we get the options set for Haml or Sass during processing.
152 153 154 155 |
# File 'lib/massimo/config.rb', line 152 def (lib_name) return ("sass") if lib_name == "scss" send("#{lib_name}_options") || send(lib_name) || {} end |
#output_path ⇒ Object
The full, expanded path to the output directory.
56 57 58 |
# File 'lib/massimo/config.rb', line 56 def output_path File. super end |
#path_for(resource_name) ⇒ Object
Get a full, expanded path for the given resource name. This is either set in the configuration or determined dynamically based on the name.
131 132 133 134 135 136 137 |
# File 'lib/massimo/config.rb', line 131 def path_for(resource_name) if resource_path = send("#{resource_name}_path") File. resource_path else File.join source_path, resource_name.to_s end end |
#source_path ⇒ Object
The full, expanded path to the source directory.
51 52 53 |
# File 'lib/massimo/config.rb', line 51 def source_path File. super end |
#url_for(resource_name) ⇒ Object
Get the configured URL for th given resource name.
140 141 142 |
# File 'lib/massimo/config.rb', line 140 def url_for(resource_name) File.join base_url, send("#{resource_name}_url") || resources_url end |