Module: HoganAssets::Config
Overview
Change config options in an initializer:
HoganAssets::Config.template_extensions = [‘mustache’]
Or in a block:
HoganAssets::Config.configure do |config|
config.lambda_support = false
config.path_prefix = 'templates'
config.template_extensions = ['mustache', 'hamstache', 'slimstache']
config.[:ugly] = true
config.[:pretty] = false
end
Or change config options in a YAML file (config/hogan_assets.yml):
defaults: &defaults
lambda_support: false
path_prefix: 'templates'
template_extensions:
- 'hamstache'
- 'slimstache'
template_namespace: 'JST'
haml_options:
ugly: true
slim_options:
pretty: false
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
Instance Attribute Summary collapse
- #env ⇒ Object
- #haml_options ⇒ Object
- #hamstache_extensions ⇒ Object
-
#lambda_support ⇒ Object
writeonly
Sets the attribute lambda_support.
- #path_prefix ⇒ Object
- #slim_options ⇒ Object
- #slimstache_extensions ⇒ Object
- #template_extensions ⇒ Object
- #template_namespace ⇒ Object
Instance Method Summary collapse
- #configure {|_self| ... } ⇒ Object
- #haml_available? ⇒ Boolean
- #lambda_support? ⇒ Boolean
- #load_yml! ⇒ Object
- #slim_available? ⇒ Boolean
- #yml ⇒ Object
- #yml_exists? ⇒ Boolean
Instance Attribute Details
#env ⇒ Object
48 49 50 51 52 53 54 55 56 |
# File 'lib/hogan_assets/config.rb', line 48 def env @env ||= if defined? Rails Rails.env elsif ENV['RACK_ENV'] ENV['RACK_ENV'] else 'development' end end |
#haml_options ⇒ Object
62 63 64 |
# File 'lib/hogan_assets/config.rb', line 62 def @haml_options ||= {} end |
#hamstache_extensions ⇒ Object
103 104 105 |
# File 'lib/hogan_assets/config.rb', line 103 def hamstache_extensions @hamstache_extensions ||= ['hamstache'] end |
#lambda_support=(value) ⇒ Object (writeonly)
Sets the attribute lambda_support
41 42 43 |
# File 'lib/hogan_assets/config.rb', line 41 def lambda_support=(value) @lambda_support = value end |
#path_prefix ⇒ Object
83 84 85 |
# File 'lib/hogan_assets/config.rb', line 83 def path_prefix @path_prefix ||= 'templates' end |
#slim_options ⇒ Object
91 92 93 |
# File 'lib/hogan_assets/config.rb', line 91 def @slim_options ||= {} end |
#slimstache_extensions ⇒ Object
107 108 109 |
# File 'lib/hogan_assets/config.rb', line 107 def slimstache_extensions @slimstache_extensions ||= ['slimstache'] end |
#template_extensions ⇒ Object
99 100 101 |
# File 'lib/hogan_assets/config.rb', line 99 def template_extensions @template_extensions ||= "mustache#{' hamstache' if haml_available?}#{' slimstache' if slim_available?}".split end |
#template_namespace ⇒ Object
95 96 97 |
# File 'lib/hogan_assets/config.rb', line 95 def template_namespace @template_namespace ||= 'HoganTemplates' end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
44 45 46 |
# File 'lib/hogan_assets/config.rb', line 44 def configure yield self end |
#haml_available? ⇒ Boolean
58 59 60 |
# File 'lib/hogan_assets/config.rb', line 58 def haml_available? defined? ::Haml::Engine end |
#lambda_support? ⇒ Boolean
66 67 68 |
# File 'lib/hogan_assets/config.rb', line 66 def lambda_support? @lambda_support end |
#load_yml! ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/hogan_assets/config.rb', line 70 def load_yml! @lambda_support = yml['lambda_support'] if yml.has_key? 'lambda_support' @path_prefix = yml['path_prefix'] if yml.has_key? 'path_prefix' @template_extensions = yml['template_extensions'] if yml.has_key? 'template_extensions' @template_namespace = yml['template_namespace'] if yml.has_key? 'template_namespace' @haml_options = yml['haml_options'] if yml.has_key? 'haml_options' @slim_options = yml['slim_options'] if yml.has_key? 'slim_options' @slimstache_extensions = yml['slimstache_extensions'] if yml.has_key? 'slimstache_extensions' @hamstache_extensions = yml['hamstache_extensions'] if yml.has_key? 'hamstache_extensions' symbolize(@haml_options) if @haml_options symbolize(@slim_options) if @slim_options end |
#slim_available? ⇒ Boolean
87 88 89 |
# File 'lib/hogan_assets/config.rb', line 87 def slim_available? defined? ::Slim::Engine end |
#yml ⇒ Object
111 112 113 114 115 116 117 |
# File 'lib/hogan_assets/config.rb', line 111 def yml begin @yml ||= (YAML.load(IO.read yml_path)[env] rescue nil) || {} rescue Psych::SyntaxError @yml = {} end end |
#yml_exists? ⇒ Boolean
119 120 121 |
# File 'lib/hogan_assets/config.rb', line 119 def yml_exists? File.exists? yml_path end |