Class: Yass::Source

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

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_pathObject (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_matterObject (readonly)

Returns the value of attribute front_matter.



9
10
11
# File 'lib/yass/source.rb', line 9

def front_matter
  @front_matter
end

#pathObject (readonly)

Returns the value of attribute path.



9
10
11
# File 'lib/yass/source.rb', line 9

def path
  @path
end

#siteObject (readonly)

Returns the value of attribute site.



9
10
11
# File 'lib/yass/source.rb', line 9

def site
  @site
end

#src_pathObject (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

#contentObject



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)

#layoutObject



32
# File 'lib/yass/source.rb', line 32

def layout = @layout_name == false ? nil : site.layout_cache["#{@layout_name}#{dest_path.extname}"]

#outfileObject



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"]

#sizeObject



42
# File 'lib/yass/source.rb', line 42

def size = @size ||= File.stat(path).size

#titleObject



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