Module: HoganAssets::Config

Extended by:
Config
Included in:
HoganAssets, Config
Defined in:
lib/hogan_assets/config.rb

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.haml_options[:ugly] = true
config.slim_options[: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

Instance Method Summary collapse

Instance Attribute Details

#envObject



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_optionsObject



62
63
64
# File 'lib/hogan_assets/config.rb', line 62

def haml_options
  @haml_options ||= {}
end

#hamstache_extensionsObject



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

Parameters:

  • value

    the value to set the attribute lambda_support to.



41
42
43
# File 'lib/hogan_assets/config.rb', line 41

def lambda_support=(value)
  @lambda_support = value
end

#path_prefixObject



83
84
85
# File 'lib/hogan_assets/config.rb', line 83

def path_prefix
  @path_prefix ||= 'templates'
end

#slim_optionsObject



91
92
93
# File 'lib/hogan_assets/config.rb', line 91

def slim_options
  @slim_options ||= {}
end

#slimstache_extensionsObject



107
108
109
# File 'lib/hogan_assets/config.rb', line 107

def slimstache_extensions
  @slimstache_extensions ||= ['slimstache']
end

#template_extensionsObject



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_namespaceObject



95
96
97
# File 'lib/hogan_assets/config.rb', line 95

def template_namespace
  @template_namespace ||= 'HoganTemplates'
end

Instance Method Details

#configure {|_self| ... } ⇒ Object

Yields:

  • (_self)

Yield Parameters:



44
45
46
# File 'lib/hogan_assets/config.rb', line 44

def configure
  yield self
end

#haml_available?Boolean

Returns:

  • (Boolean)


58
59
60
# File 'lib/hogan_assets/config.rb', line 58

def haml_available?
  defined? ::Haml::Engine
end

#lambda_support?Boolean

Returns:

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

Returns:

  • (Boolean)


87
88
89
# File 'lib/hogan_assets/config.rb', line 87

def slim_available?
  defined? ::Slim::Engine
end

#ymlObject



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

Returns:

  • (Boolean)


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

def yml_exists?
  File.exists? yml_path
end