Module: Almanack::ServerContext::Environment
- Included in:
- Almanack::Server
- Defined in:
- lib/almanack/server/environment.rb
Instance Method Summary collapse
- #auto_render_asset(*args) ⇒ Object
- #auto_render_template(asset) ⇒ Object
- #basename(file) ⇒ Object
- #locate_asset(name, within: path) ⇒ Object
- #register_sass_loadpaths! ⇒ Object
- #theme_stylesheet_path ⇒ Object
Instance Method Details
#auto_render_asset(*args) ⇒ Object
23 24 25 |
# File 'lib/almanack/server/environment.rb', line 23 def auto_render_asset(*args) auto_render_template locate_asset(*args) end |
#auto_render_template(asset) ⇒ Object
17 18 19 20 21 |
# File 'lib/almanack/server/environment.rb', line 17 def auto_render_template(asset) renderer = asset.extname.split(".").last content = asset.read respond_to?(renderer) ? send(renderer, content) : content end |
#basename(file) ⇒ Object
4 5 6 |
# File 'lib/almanack/server/environment.rb', line 4 def basename(file) Pathname(file).split.last.to_s.split(".", 2).first end |
#locate_asset(name, within: path) ⇒ Object
8 9 10 11 12 13 14 15 |
# File 'lib/almanack/server/environment.rb', line 8 def locate_asset(name, within: path) name = basename(name) path = settings.root.join(within) available = Pathname.glob(path.join("*")) asset = available.find { |path| basename(path) == name } raise "Could not find stylesheet #{name} inside #{available}" if asset.nil? asset end |
#register_sass_loadpaths! ⇒ Object
31 32 33 34 35 |
# File 'lib/almanack/server/environment.rb', line 31 def register_sass_loadpaths! if !SassC.load_paths.include?(theme_stylesheet_path) SassC.load_paths << theme_stylesheet_path end end |
#theme_stylesheet_path ⇒ Object
27 28 29 |
# File 'lib/almanack/server/environment.rb', line 27 def theme_stylesheet_path settings.root.join('stylesheets') end |