Class: Yass::Source
- Inherits:
-
Object
- Object
- Yass::Source
- Defined in:
- lib/yass/source.rb
Constant Summary collapse
- EXT_CONVERSIONS =
{"md" => "html"}.freeze
- YAML_HEADER =
/\A---\s*\n/- FRONT_MATTER =
/\A(?<matter>---\s*\n.*^---\s*\n?)(?<content>.+)?$/m
Instance Attribute Summary collapse
-
#dest_path ⇒ Object
readonly
Returns the value of attribute dest_path.
-
#front_matter ⇒ Object
readonly
Returns the value of attribute front_matter.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
-
#site ⇒ Object
readonly
Returns the value of attribute site.
-
#src_path ⇒ Object
readonly
Returns the value of attribute src_path.
Instance Method Summary collapse
- #content ⇒ Object
- #dynamic? ⇒ Boolean
-
#initialize(site, path) ⇒ Source
constructor
A new instance of Source.
- #layout ⇒ Object
- #outfile ⇒ Object
- #published? ⇒ Boolean
- #size ⇒ Object
- #title ⇒ Object
Constructor Details
#initialize(site, path) ⇒ Source
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/yass/source.rb', line 11 def initialize(site, path) @site = site @path = path @src_path = path.relative_path_from site.src_dir @dest_path = src_path.dirname.join(dest_filename) @front_matter, @content = parse_content @title = front_matter.delete "title" if front_matter.key? "title" @layout_name = front_matter.delete "layout" if front_matter.key? "layout" @layout_name = "default" if @layout_name.nil? end |
Instance Attribute Details
#dest_path ⇒ Object (readonly)
Returns the value of attribute dest_path.
9 10 11 |
# File 'lib/yass/source.rb', line 9 def dest_path @dest_path end |
#front_matter ⇒ Object (readonly)
Returns the value of attribute front_matter.
9 10 11 |
# File 'lib/yass/source.rb', line 9 def front_matter @front_matter end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/yass/source.rb', line 9 def path @path end |
#site ⇒ Object (readonly)
Returns the value of attribute site.
9 10 11 |
# File 'lib/yass/source.rb', line 9 def site @site end |
#src_path ⇒ Object (readonly)
Returns the value of attribute src_path.
9 10 11 |
# File 'lib/yass/source.rb', line 9 def src_path @src_path end |
Instance Method Details
#content ⇒ Object
36 |
# File 'lib/yass/source.rb', line 36 def content = @content ||= path.read |
#dynamic? ⇒ Boolean
34 |
# File 'lib/yass/source.rb', line 34 def dynamic? = !!(/\.(liquid|md)(\..+)?$/ =~ path.basename.to_s || layout || @has_front_matter) |
#layout ⇒ Object
32 |
# File 'lib/yass/source.rb', line 32 def layout = @layout_name == false ? nil : site.layout_cache["#{@layout_name}#{dest_path.extname}"] |
#outfile ⇒ Object
38 |
# File 'lib/yass/source.rb', line 38 def outfile = site.dest_dir.join(dest_path) |
#published? ⇒ Boolean
40 |
# File 'lib/yass/source.rb', line 40 def published? = front_matter["published"].nil? ? true : !!front_matter["published"] |
#size ⇒ Object
42 |
# File 'lib/yass/source.rb', line 42 def size = @size ||= File.stat(path).size |
#title ⇒ Object
23 24 25 26 27 28 29 30 |
# File 'lib/yass/source.rb', line 23 def title return @title if @title fname = dest_path.basename.sub(/\..+$/, "").to_s fname = src_path.dirname.basename.to_s if fname == "index" fname = "Home" if fname == "." @title = fname.gsub(/[_-]+/, " ").split(/ +/).map(&:capitalize).join(" ") end |