Module: LiquidAssets::Config

Extended by:
Config
Included in:
LiquidAssets, Config
Defined in:
lib/liquid_assets/config.rb

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

Instance Method Summary collapse

Instance Attribute Details

#content_providerObject



88
89
90
# File 'lib/liquid_assets/config.rb', line 88

def content_provider
    @content_provider ||= lambda{|path| false }
end

#envObject



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

#filtersObject



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

def filters
    @filters ||= LiquidAssets::Filters
end

#globalsObject



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

def globals
    ( @globals && @globals.is_a?(Proc) ) ? @globals.call : @globals ||= {}
end

#namespaceObject



101
102
103
# File 'lib/liquid_assets/config.rb', line 101

def namespace
  @namespace ||= 'LQT'
end

#path_prefixObject



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

Yields:

  • (_self)

Yield Parameters:



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_pathObject



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_pathObject



94
95
96
# File 'lib/liquid_assets/config.rb', line 94

def template_root_path
    root_path.join( 'app','assets','templates' )
end

#ymlObject



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

Returns:

  • (Boolean)


113
114
115
# File 'lib/liquid_assets/config.rb', line 113

def yml_exists?
  File.exists? yml_path
end