Class: Zine::Page

Inherits:
Object
  • Object
show all
Defined in:
lib/zine/page.rb

Overview

A page on the site where the content comes from a file’s markdown, and the destination’s location mirrors its own

Direct Known Subclasses

DataPage, Post

Defined Under Namespace

Classes: FormattedData, TagData

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(md_file_name, dest, templates, site_options) ⇒ Page

Returns a new instance of Page.



77
78
79
80
81
82
83
84
85
86
# File 'lib/zine/page.rb', line 77

def initialize(md_file_name, dest, templates, site_options)
  @source_file = md_file_name
  file_parts = File.read(md_file_name).split('---', 3)
  @formatted_data = FormattedData.new(parse_yaml(file_parts[1],
                                                 md_file_name),
                                      site_options)
  @dest_path = dest
  @raw_text = file_parts[2]
  init_templates(templates)
end

Instance Attribute Details

#dest_pathObject (readonly)

PostsAndHeadlines.one_new_post



20
21
22
# File 'lib/zine/page.rb', line 20

def dest_path
  @dest_path
end

#formatted_dataObject

used in zine notice –



18
19
20
# File 'lib/zine/page.rb', line 18

def formatted_data
  @formatted_data
end

#source_fileObject

used in zine notice –



18
19
20
# File 'lib/zine/page.rb', line 18

def source_file
  @source_file
end

#template_bundleObject (readonly)

PostsAndHeadlines.one_new_post



20
21
22
# File 'lib/zine/page.rb', line 20

def template_bundle
  @template_bundle
end

Class Method Details

.slug(text) ⇒ Object



96
97
98
99
100
# File 'lib/zine/page.rb', line 96

def self.slug(text)
  text.downcase
      .gsub(/[^a-z0-9]+/, '-')
      .gsub(/^-|-$/, '')
end

Instance Method Details

#process(string_or_file_writer) ⇒ Object



88
89
90
91
92
93
94
# File 'lib/zine/page.rb', line 88

def process(string_or_file_writer)
  parse_markdown
  html = template_the_html

  compressor = HtmlCompressor::Compressor.new
  string_or_file_writer.write(@dest_path, compressor.compress(html))
end