Module: LiquidAssets::Config
Overview
Change config options in an initializer:
LiquidAssets::Config.namespace = 'LT'
Or in a block:
LiquidAssets::Config.configure do |config|
config.path_prefix = 'app/assets/templates'
config.filters = MyFilterModule
config.namespace = 'LQT'
end
Or change config options in a YAML file (config/liquid_assets.yml):
defaults: &defaults
path_prefix: 'templates'
namespace: 'LQT'
globals:
company: 'BigCorp Inc'
development:
<<: *defaults
test:
<<: *defaults
production:
<<: *defaults
Instance Attribute Summary collapse
- #content_provider ⇒ Object
- #env ⇒ Object
- #filters ⇒ Object
- #globals ⇒ Object
- #namespace ⇒ Object
- #path_prefix ⇒ Object
Instance Method Summary collapse
- #configure {|_self| ... } ⇒ Object
- #load_yml! ⇒ Object
- #root_path ⇒ Object
- #template_root_path ⇒ Object
- #yml ⇒ Object
- #yml_exists? ⇒ Boolean
Instance Attribute Details
#content_provider ⇒ Object
88 89 90 |
# File 'lib/liquid_assets/config.rb', line 88 def content_provider @content_provider ||= lambda{|path| false } end |
#env ⇒ Object
60 61 62 63 64 65 66 67 68 |
# File 'lib/liquid_assets/config.rb', line 60 def env @env ||= if defined? Rails Rails.env elsif ENV['RACK_ENV'] ENV['RACK_ENV'] else 'development' end end |
#filters ⇒ Object
98 99 100 |
# File 'lib/liquid_assets/config.rb', line 98 def filters @filters ||= LiquidAssets::Filters end |
#globals ⇒ Object
91 92 93 |
# File 'lib/liquid_assets/config.rb', line 91 def globals ( @globals && @globals.is_a?(Proc) ) ? @globals.call : @globals ||= {} end |
#namespace ⇒ Object
101 102 103 |
# File 'lib/liquid_assets/config.rb', line 101 def namespace @namespace ||= 'LQT' end |
#path_prefix ⇒ Object
76 77 78 |
# File 'lib/liquid_assets/config.rb', line 76 def path_prefix @path_prefix ||= File.join('app','assets','templates') end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
56 57 58 |
# File 'lib/liquid_assets/config.rb', line 56 def configure yield self end |
#load_yml! ⇒ Object
70 71 72 73 74 |
# File 'lib/liquid_assets/config.rb', line 70 def load_yml! %{path_prefix namespace globals}.each do | name | self.instance_variable_set( "@#{name}", yml[name] ) if yaml.has_key?(name) end end |
#root_path ⇒ Object
80 81 82 83 84 85 86 |
# File 'lib/liquid_assets/config.rb', line 80 def root_path if defined? Rails Rails.root else Pathname.new('.') end end |
#template_root_path ⇒ Object
94 95 96 |
# File 'lib/liquid_assets/config.rb', line 94 def template_root_path root_path.join( 'app','assets','templates' ) end |
#yml ⇒ Object
105 106 107 108 109 110 111 |
# File 'lib/liquid_assets/config.rb', line 105 def yml begin @yml ||= (YAML.load(IO.read yml_path)[env] rescue nil) || {} rescue Psych::SyntaxError @yml = {} end end |
#yml_exists? ⇒ Boolean
113 114 115 |
# File 'lib/liquid_assets/config.rb', line 113 def yml_exists? File.exists? yml_path end |