Class: HighFive::Config

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

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = nil) ⇒ Config

Returns a new instance of Config.



92
93
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
# File 'lib/high_five/config.rb', line 92

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.meta.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.meta = config.meta
    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
  @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

Yields:



41
42
43
44
45
46
47
48
# File 'lib/high_five/config.rb', line 41

def self.configure(&block) 
  @@instance = HighFive::Config.new
  yield @@instance

  if @@instance.root.nil?
    raise "HighFive::Config.root is required"
  end
end

.instance ⇒ Object



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

def self.instance
  @@instance
end

.load ⇒ Object



50
51
52
53
54
55
56
57
# File 'lib/high_five/config.rb', line 50

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



126
127
128
# File 'lib/high_five/config.rb', line 126

def assets(path)
  @static_assets << path.dup
end

#build_platform_config(platform) ⇒ Object



63
64
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
# File 'lib/high_five/config.rb', line 63

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.meta ||= self.meta
    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



147
148
149
150
151
152
153
154
# File 'lib/high_five/config.rb', line 147

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



161
162
163
164
165
166
# File 'lib/high_five/config.rb', line 161

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



130
131
132
# File 'lib/high_five/config.rb', line 130

def javascripts(path)
  @static_javascripts << path.dup
end

#platform(name) {|| ... } ⇒ Object

Yields:

  • ()


142
143
144
145
# File 'lib/high_five/config.rb', line 142

def platform(name, &block)
  @platform_configs[name.to_s] = HighFive::Config.new
  yield @platform_configs[name.to_s]
end

#sass(path) ⇒ Object



134
135
136
# File 'lib/high_five/config.rb', line 134

def sass(path) 
  @sass_files << path.dup
end

#setting(hash) ⇒ Object Also known as: settings



156
157
158
# File 'lib/high_five/config.rb', line 156

def setting(hash)
  @js_settings.merge!(hash)
end

#stylesheets(path) ⇒ Object



138
139
140
# File 'lib/high_five/config.rb', line 138

def stylesheets(path)
  @static_stylesheets << path.dup
end

#windows! ⇒ Object



168
169
170
171
172
# File 'lib/high_five/config.rb', line 168

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