Class: Gakubuchi::Template
- Inherits:
-
Object
- Object
- Gakubuchi::Template
- Extended by:
- Forwardable
- Defined in:
- lib/gakubuchi/template.rb
Instance Attribute Summary collapse
-
#extname ⇒ Object
readonly
Returns the value of attribute extname.
-
#source_path ⇒ Object
readonly
Returns the value of attribute source_path.
Class Method Summary collapse
Instance Method Summary collapse
- #destination_path ⇒ Object
- #digest_path ⇒ Object
-
#initialize(source_path) ⇒ Template
constructor
A new instance of Template.
- #logical_path ⇒ Object
Constructor Details
#initialize(source_path) ⇒ Template
Returns a new instance of Template.
22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/gakubuchi/template.rb', line 22 def initialize(source_path) path = ::Pathname.new(source_path) root = self.class.root @extname = extract_extname(path) @source_path = path.absolute? ? path : root.join(path) case when !@extname.include?("html") fail Error::InvalidTemplate, "source path must refer to a template file" when !@source_path.fnmatch?(root.join("*").to_s) fail Error::InvalidTemplate, "template must exist in #{root}" end end |
Instance Attribute Details
#extname ⇒ Object (readonly)
Returns the value of attribute extname.
5 6 7 |
# File 'lib/gakubuchi/template.rb', line 5 def extname @extname end |
#source_path ⇒ Object (readonly)
Returns the value of attribute source_path.
5 6 7 |
# File 'lib/gakubuchi/template.rb', line 5 def source_path @source_path end |
Class Method Details
.all ⇒ Object
14 15 16 |
# File 'lib/gakubuchi/template.rb', line 14 def self.all ::Dir.glob(root.join("**/*.html*")).map { |source_path| new(source_path) } end |
.root ⇒ Object
18 19 20 |
# File 'lib/gakubuchi/template.rb', line 18 def self.root ::Rails.root.join("app/assets", ::Gakubuchi.configuration.template_directory) end |
Instance Method Details
#destination_path ⇒ Object
37 38 39 |
# File 'lib/gakubuchi/template.rb', line 37 def destination_path ::Rails.public_path.join(logical_path) end |
#digest_path ⇒ Object
41 42 43 44 45 46 |
# File 'lib/gakubuchi/template.rb', line 41 def digest_path asset = assets.find_asset(logical_path) return if asset.nil? ::Pathname.new(::File.join(::Rails.public_path, app.config.assets.prefix, asset.digest_path)) end |
#logical_path ⇒ Object
48 49 50 51 |
# File 'lib/gakubuchi/template.rb', line 48 def logical_path dirname = source_path.relative_path_from(self.class.root).dirname ::Pathname.new(dirname).join("#{basename(extname)}.html") end |