Class: Gluey::Material
- Inherits:
-
Object
- Object
- Gluey::Material
- Defined in:
- lib/gluey/material.rb
Instance Attribute Summary collapse
-
#asset ⇒ Object
Returns the value of attribute asset.
-
#file_extension ⇒ Object
Returns the value of attribute file_extension.
-
#glue ⇒ Object
readonly
Returns the value of attribute glue.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#public_dir ⇒ Object
Returns the value of attribute public_dir.
Instance Method Summary collapse
- #add_item(declaration) ⇒ Object
- #add_path(path) ⇒ Object
- #find_base_file(path) ⇒ Object
-
#initialize(name, glue, context) {|_self| ... } ⇒ Material
constructor
A new instance of Material.
- #is_listed?(path, file = nil) ⇒ Boolean
- #list_all_items ⇒ Object
- #to_s ⇒ Object
Constructor Details
#initialize(name, glue, context) {|_self| ... } ⇒ Material
Returns a new instance of Material.
8 9 10 11 12 13 14 15 16 17 |
# File 'lib/gluey/material.rb', line 8 def initialize(name, glue, context) @name = name.to_sym @glue = glue @context = context @asset = name.to_s @paths = [] @items = [] yield self if block_given? @file_extension ||= @asset.dup end |
Instance Attribute Details
#asset ⇒ Object
Returns the value of attribute asset.
6 7 8 |
# File 'lib/gluey/material.rb', line 6 def asset @asset end |
#file_extension ⇒ Object
Returns the value of attribute file_extension.
6 7 8 |
# File 'lib/gluey/material.rb', line 6 def file_extension @file_extension end |
#glue ⇒ Object (readonly)
Returns the value of attribute glue.
5 6 7 |
# File 'lib/gluey/material.rb', line 5 def glue @glue end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
5 6 7 |
# File 'lib/gluey/material.rb', line 5 def name @name end |
#public_dir ⇒ Object
Returns the value of attribute public_dir.
6 7 8 |
# File 'lib/gluey/material.rb', line 6 def public_dir @public_dir end |
Instance Method Details
#add_item(declaration) ⇒ Object
23 24 25 |
# File 'lib/gluey/material.rb', line 23 def add_item(declaration) @items << declaration end |
#add_path(path) ⇒ Object
19 20 21 |
# File 'lib/gluey/material.rb', line 19 def add_path(path) @paths << path end |
#find_base_file(path) ⇒ Object
44 45 46 47 48 49 50 51 52 |
# File 'lib/gluey/material.rb', line 44 def find_base_file(path) paths.each do |base_path| p = "#{base_path}/#{path}.#{@file_extension}"; return p if File.exists? p p = "#{p}.erb"; return p if File.exists? p p = "#{base_path}/#{path}/index.#{@file_extension}"; return p if File.exists? p p = "#{p}.erb"; return p if File.exists? p end raise(::Gluey::FileNotFound.new "#{to_s} cannot find base file for #{path}") end |
#is_listed?(path, file = nil) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/gluey/material.rb', line 27 def is_listed?(path, file=nil) @items.any? do |items_declaration| case items_declaration when String path == items_declaration when Regexp path =~ items_declaration when Proc items_declaration[path, file] end end end |
#list_all_items ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/gluey/material.rb', line 54 def list_all_items list = [] paths.map do |base_path| glob_path = "#{base_path}/**/*.#{@file_extension}" files = Dir[glob_path] + Dir["#{glob_path}.erb"] files.select do |file| path = file[/^#{base_path}\/(.+)\.#{@file_extension}(?:\.erb)?$/, 1] path.gsub! /\/index$/, '' list << path if is_listed? path, file end end list.uniq end |
#to_s ⇒ Object
40 41 42 |
# File 'lib/gluey/material.rb', line 40 def to_s "Material #{@name}" end |