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.



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/high_five/config.rb', line 70

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
  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

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def asset_paths
  @asset_paths
end

#compass_dir ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def compass_dir
  @compass_dir
end

#destination(*args) ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def destination
  @destination
end

#dev_index(*args) ⇒ Object

easy setters



4
5
6
# File 'lib/high_five/config.rb', line 4

def dev_index
  @dev_index
end

#is_environment ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def is_environment
  @is_environment
end

#js_settings ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def js_settings
  @js_settings
end

#meta ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def meta
  @meta
end

#minify ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def minify
  @minify
end

#page_title ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def page_title
  @page_title
end

#platform_configs ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def platform_configs
  @platform_configs
end

#root ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def root
  @root
end

#sass_files ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def sass_files
  @sass_files
end

#static_assets ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def static_assets
  @static_assets
end

#static_javascripts ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def static_javascripts
  @static_javascripts
end

#static_stylesheets ⇒ Object

Root of the project



4
5
6
# File 'lib/high_five/config.rb', line 4

def static_stylesheets
  @static_stylesheets
end

Class Method Details

.configure {|@@instance| ... } ⇒ Object

Yields:



21
22
23
24
25
26
27
28
# File 'lib/high_five/config.rb', line 21

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

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

.instance ⇒ Object



39
40
41
# File 'lib/high_five/config.rb', line 39

def self.instance
  @@instance
end

.load ⇒ Object



30
31
32
33
34
35
36
37
# File 'lib/high_five/config.rb', line 30

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



98
99
100
# File 'lib/high_five/config.rb', line 98

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

#build_platform_config(platform) ⇒ Object



43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/high_five/config.rb', line 43

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
    new_config.compass_dir ||= self.compass_dir
    new_config.dev_index ||= self.dev_index
    new_config.minify ||= self.minify
    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

#compass(config_dir) ⇒ Object



110
111
112
# File 'lib/high_five/config.rb', line 110

def compass(config_dir)
  @compass_dir = config_dir
end

#environment(name, &block) ⇒ Object



123
124
125
126
127
128
129
130
# File 'lib/high_five/config.rb', line 123

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



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

def high_five_javascript
  js = '<script type="text/javascript">'
  js += "if(typeof(window.HighFive)==='undefined'){window.HighFive={};}window.HighFive.Settings=#{JSON.dump(js_settings)};"
  js += '</script>'
  js
end

#javascripts(path) ⇒ Object



102
103
104
# File 'lib/high_five/config.rb', line 102

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

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

Yields:

  • ()


118
119
120
121
# File 'lib/high_five/config.rb', line 118

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

#sass(path) ⇒ Object



106
107
108
# File 'lib/high_five/config.rb', line 106

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

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



132
133
134
# File 'lib/high_five/config.rb', line 132

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

#stylesheets(path) ⇒ Object



114
115
116
# File 'lib/high_five/config.rb', line 114

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