Class: HighFive::Config
- Inherits:
-
Object
- Object
- HighFive::Config
- Defined in:
- lib/high_five/config.rb
Instance Attribute Summary collapse
-
#asset_paths ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#is_environment ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#js_settings ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#meta ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#platform_configs ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#sass_files ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#static_assets ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#static_javascripts ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
-
#static_stylesheets ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }.
Class Method Summary collapse
-
.config_setting(*settings) ⇒ Object
shorthand for me to define lots and lots of config settings that need to be handled as attr_accessible, settable via setting(blah) instead of settings=blah, and also persisted to derived platform configs.
- .configure {|@@instance| ... } ⇒ Object
- .instance ⇒ Object
- .load ⇒ Object
Instance Method Summary collapse
- #assets(path) ⇒ Object
- #build_platform_config(platform) ⇒ Object
- #environment(name, &block) ⇒ Object
- #high_five_javascript ⇒ Object
-
#initialize(config = nil) ⇒ Config
constructor
A new instance of Config.
- #javascripts(path) ⇒ Object
- #platform(name) {|| ... } ⇒ Object
- #sass(path) ⇒ Object
- #setting(hash) ⇒ Object (also: #settings)
- #stylesheets(path) ⇒ Object
- #windows! ⇒ Object
Constructor Details
#initialize(config = nil) ⇒ Config
Returns a new instance of Config.
94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/high_five/config.rb', line 94 def initialize(config=nil) if config @static_assets = config.static_assets.dup @static_javascripts = config.static_javascripts.dup @static_stylesheets = config.static_stylesheets.dup @sass_files = config.sass_files.dup @meta = config..dup @asset_paths = config.asset_paths.dup @js_settings = config.js_settings.dup self.root = config.root self.destination = config.destination self.dev_index = config.dev_index self.page_title = config.page_title self. = config. self.minify = config.minify self.manifest = config.manifest @@config_variables.each do |svar| if (self.instance_variable_get(svar).nil?) self.instance_variable_set(svar, config.instance_variable_get(svar)) end end else @static_assets = [] @static_javascripts = [] @static_stylesheets = [] @sass_files = [] @meta = {} @platform_configs = {} @asset_paths = [] @js_settings = {} end @is_environment = false end |
Instance Attribute Details
#asset_paths ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def asset_paths @asset_paths end |
#is_environment ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def is_environment @is_environment end |
#js_settings ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def js_settings @js_settings end |
#meta ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def @meta end |
#platform_configs ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def platform_configs @platform_configs end |
#sass_files ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def sass_files @sass_files end |
#static_assets ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def static_assets @static_assets end |
#static_javascripts ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def static_javascripts @static_javascripts end |
#static_stylesheets ⇒ Object
config.meta << { http-equiv: "Content-Type" content: "text/html; charset=utf-8" }
4 5 6 |
# File 'lib/high_five/config.rb', line 4 def static_stylesheets @static_stylesheets end |
Class Method Details
.config_setting(*settings) ⇒ Object
shorthand for me to define lots and lots of config settings that need to be handled as attr_accessible, settable via setting(blah) instead of settings=blah, and also persisted to derived platform configs
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/high_five/config.rb', line 18 def self.config_setting(*settings) config_variables = [] settings.each do |setting| attr_accessor setting define_method setting do |*args| var = "@#{setting}".to_sym config_variables << var instance_variable_set(var, args[0]) if args.length == 1 instance_variable_get(var) end end @@config_variables = config_variables end |
.configure {|@@instance| ... } ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/high_five/config.rb', line 43 def self.configure(&block) @@instance = HighFive::Config.new yield @@instance if @@instance.root.nil? raise "HighFive::Config.root is required" end end |
.instance ⇒ Object
61 62 63 |
# File 'lib/high_five/config.rb', line 61 def self.instance @@instance end |
.load ⇒ Object
52 53 54 55 56 57 58 59 |
# File 'lib/high_five/config.rb', line 52 def self.load begin require File.join(Dir.pwd, "config", "high_five.rb") rescue LoadError raise "high_five configuration not found, forgot to run 'hi5 init'?" end return @@instance end |
Instance Method Details
#assets(path) ⇒ Object
128 129 130 |
# File 'lib/high_five/config.rb', line 128 def assets(path) @static_assets << path.dup end |
#build_platform_config(platform) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/high_five/config.rb', line 65 def build_platform_config(platform) if @platform_configs[platform.to_s] new_config = HighFive::Config.new(@platform_configs[platform.to_s]) new_config.root ||= self.root new_config.destination ||= self.destination new_config. ||= self. new_config.page_title ||= self.page_title new_config.static_assets += self.static_assets new_config.static_javascripts += self.static_javascripts new_config.static_stylesheets += self.static_stylesheets new_config.sass_files += self.sass_files new_config.asset_paths += self.asset_paths @@config_variables.each do |svar| if (new_config.instance_variable_get(svar).nil?) new_config.instance_variable_set(svar, self.instance_variable_get(svar)) end end new_config.js_settings.merge! self.js_settings do |key, new_setting, old_setting| new_setting || old_setting #don't clobber settings from the parent end new_config.platform_configs = @platform_configs.reject do |key, platform_config| key == platform end return new_config else return self end end |
#environment(name, &block) ⇒ Object
149 150 151 152 153 154 155 156 |
# File 'lib/high_five/config.rb', line 149 def environment(name, &block) platform(name, &block) platform_config = @platform_configs[name.to_s] platform_config.is_environment = true if (name.to_s == 'production') platform_config.minify = :uglifier if platform_config.minify.nil? end end |
#high_five_javascript ⇒ Object
163 164 165 166 167 168 |
# File 'lib/high_five/config.rb', line 163 def high_five_javascript js = '<script type="text/javascript">' js += "if(typeof(window.HighFive)==='undefined'){window.HighFive={};}window.HighFive.Settings=#{MultiJson.dump(js_settings)};" js += '</script>' js end |
#javascripts(path) ⇒ Object
132 133 134 |
# File 'lib/high_five/config.rb', line 132 def javascripts(path) @static_javascripts << path.dup end |
#platform(name) {|| ... } ⇒ Object
144 145 146 147 |
# File 'lib/high_five/config.rb', line 144 def platform(name, &block) @platform_configs[name.to_s] = HighFive::Config.new yield @platform_configs[name.to_s] end |
#sass(path) ⇒ Object
136 137 138 |
# File 'lib/high_five/config.rb', line 136 def sass(path) @sass_files << path.dup end |
#setting(hash) ⇒ Object Also known as: settings
158 159 160 |
# File 'lib/high_five/config.rb', line 158 def setting(hash) @js_settings.merge!(hash) end |
#stylesheets(path) ⇒ Object
140 141 142 |
# File 'lib/high_five/config.rb', line 140 def stylesheets(path) @static_stylesheets << path.dup end |
#windows! ⇒ Object
170 171 172 173 174 |
# File 'lib/high_five/config.rb', line 170 def windows! ExecJS::Runtimes::JScript.instance_variable_set(:"@encoding", "UTF-8") ExecJS::Runtimes::JScript.instance_variable_set(:"@command", "cscript //E:jscript //Nologo") ExecJS::Runtimes::JScript.instance_variable_set(:"@binary", "cscript //E:jscript //Nologo") end |