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.



69
70
71
72
73
74
75
76
77
78
# File 'lib/zine/page.rb', line 69

def initialize(md_file_name, dest, templates, site_options)
  @source_file = md_file_name
  file_parts = File.open(md_file_name, 'r').read.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



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

def dest_path
  @dest_path
end

#formatted_dataObject (readonly)

PostsAndHeadlines.one_new_post



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

def formatted_data
  @formatted_data
end

#source_fileObject

used in zine notice –



16
17
18
# File 'lib/zine/page.rb', line 16

def source_file
  @source_file
end

#template_bundleObject (readonly)

PostsAndHeadlines.one_new_post



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

def template_bundle
  @template_bundle
end

Class Method Details

.slug(text) ⇒ Object



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

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

Instance Method Details

#process(string_or_file_writer) ⇒ Object



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

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