Module: CSL::Loader
Overview
Base classes are exepcted to define a #parse method.
Mixin used by Locale and Style to load assets either from disk or from the network. Classes including the Loader module are expected to provide appropriate root, prefix and extension values and a parse method that will be passed the contents of the asset data.
Instance Attribute Summary collapse
-
#extension ⇒ Object
Returns the value of attribute extension.
-
#prefix ⇒ Object
Returns the value of attribute prefix.
-
#root ⇒ Object
Returns the value of attribute root.
Instance Method Summary collapse
-
#extend_name(string) ⇒ Object
Extends the passed-in string to a style/locale name, by prefixing and appending the default name prefix and extension.
-
#extend_path(string) ⇒ Object
Extends the passed-in string to a full path.
- #list ⇒ Object (also: #ls)
-
#load(input) ⇒ Style, Locale
Resolves the passed-in path/name or string and loads the asset data.
Instance Attribute Details
#extension ⇒ Object
Returns the value of attribute extension.
12 13 14 |
# File 'lib/csl/loader.rb', line 12 def extension @extension end |
#prefix ⇒ Object
Returns the value of attribute prefix.
12 13 14 |
# File 'lib/csl/loader.rb', line 12 def prefix @prefix end |
Instance Method Details
#extend_name(string) ⇒ Object
Extends the passed-in string to a style/locale name, by prefixing and appending the default name prefix and extension.
48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/csl/loader.rb', line 48 def extend_name(string) if File.extname(string.to_s).empty? name = [string, extension].compact.join else name = string.to_s.dup end unless name.start_with?(prefix.to_s) name = [prefix, name].join end name end |
#extend_path(string) ⇒ Object
Extends the passed-in string to a full path.
42 43 44 |
# File 'lib/csl/loader.rb', line 42 def extend_path(string) File.join(root.to_s, extend_name(string)) end |
#list ⇒ Object Also known as: ls
34 35 36 37 38 |
# File 'lib/csl/loader.rb', line 34 def list Dir["#{root}/#{prefix}*#{extension}"].map do |path| File.basename(path, extension).sub(/^#{prefix}/, '') end end |
#load(input) ⇒ Style, Locale
The base class is expected to define a #parse! method.
Resolves the passed-in path/name or string and loads the asset data. The data will be passed on to the #parse! method of the base class. Typically, this will return a new instance of the class.
30 31 32 |
# File 'lib/csl/loader.rb', line 30 def load(input) parse! extract_data_from(input) end |