summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2017-01-06 23:18:24 -0500
committerLuke Shumaker <lukeshu@sbcglobal.net>2017-01-06 23:18:24 -0500
commit4a3a404a5cb2a8d5be83e28cec5c539928fa30f4 (patch)
treeb6f636ba3ed0ce486941b1b9ad67cb0973699d6b /lib
parent7edb003cd1c9b53ffdff11ef85532e39f08db16d (diff)
aaaah
Diffstat (limited to 'lib')
-rw-r--r--lib/category.rb (renamed from lib/tag.rb)7
-rw-r--r--lib/config.rb9
-rw-r--r--lib/page.rb56
-rw-r--r--lib/page_index.rb45
-rw-r--r--lib/page_local.rb68
-rw-r--r--lib/page_remote.rb19
6 files changed, 122 insertions, 82 deletions
diff --git a/lib/tag.rb b/lib/category.rb
index 4009f67..266da34 100644
--- a/lib/tag.rb
+++ b/lib/category.rb
@@ -1,7 +1,7 @@
# coding: utf-8
require 'config'
-class Tag
+class Category
def initialize(abbr)
@abbr = abbr
end
@@ -9,9 +9,12 @@ class Tag
@abbr
end
def name
- Config::get.tag_name(@abbr)
+ Config::get.category_name(@abbr)
end
def html
return "<a class=\"tag #{abbr}\" href=\"/tags/#{abbr}.html\">#{name}</a>"
end
+ def atom
+ return "<category term=\"#{term}\" label=\"#{name}\" />"
+ end
end
diff --git a/lib/config.rb b/lib/config.rb
index b22eedf..4690559 100644
--- a/lib/config.rb
+++ b/lib/config.rb
@@ -41,8 +41,11 @@ class Config
def person_email(name)
return @data['person_emails'][name]
end
- # Tags
- def tag_name(abbr)
- return @data['tag_names'][abbr]
+ # Categories
+ def categories
+ return @data['categories'].keys
+ end
+ def category_name(abbr)
+ return @data['categories'][abbr]
end
end
diff --git a/lib/page.rb b/lib/page.rb
index d0b18ef..64bbaea 100644
--- a/lib/page.rb
+++ b/lib/page.rb
@@ -1,7 +1,7 @@
# coding: utf-8
require 'set'
-require 'tag'
+require 'category'
class Page
# Page is an abstract class.
@@ -9,54 +9,54 @@ class Page
# Implementors must implement several methods:
#
# def url => URI
- # def title => String
- # def author => Person
- # def content => html | nil
- # def rights => html | nil
+ # def atom_title => String
+ # def atom_author => Person
+ # def atom_content => html | nil
+ # def atom_rights => html | nil
#
- # def _tags => String | Enumerable<String>
+ # def page_categories => String | Enumerable<String>
#
- # def _published => DateTime | nil
- # def _updated => DateTime | nil
- # def _years => Enumerable<Fixnum>
+ # def page_published => DateTime | nil
+ # def page_updated => DateTime | nil
+ # def page_years => Enumerable<Fixnum>
- def tags # => Enumerable<Tag>
- if @tags.nil?
- raw = _tags
+ def atom_categories # => Enumerable<Category>
+ if @categories.nil?
+ raw = page_categories
if raw.is_a?(String)
raw = raw.split
end
- @tags = raw.map{|tag|Tag.new(tag)}
+ @categories = raw.map{|abbr|Category.new(abbr)}
end
- @tags
+ @categories
end
- def published # => DateTime | nil
+ def atom_published # => DateTime | nil
if @published.nil?
- unless _published.nil?
- @published = _published
+ unless page_published.nil?
+ @published = page_published
else
- unless _updated.nil?
- @published = _updated
+ unless page_updated.nil?
+ @published = page_updated
end
end
# sanity check
- unless _published.nil? or _updated.nil?
- if _updated < _published
- @published = _updated
+ unless page_published.nil? or page_updated.nil?
+ if page_updated < page_published
+ @published = page_updated
end
end
end
@published
end
- def updated # => DateTime | nil
+ def atom_updated # => DateTime | nil
if @updated.nil?
- unless _updated.nil?
- @updated = _updated
+ unless page_updated.nil?
+ @updated = page_updated
else
- unless _published.nil?
- @updated = _published
+ unless page_published.nil?
+ @updated = page_published
end
end
end
@@ -71,7 +71,7 @@ class Page
first = published.year
last = updated.year
- years = _years
+ years = page_years
years.add(first)
years.add(last)
diff --git a/lib/page_index.rb b/lib/page_index.rb
index 073537e..3e25813 100644
--- a/lib/page_index.rb
+++ b/lib/page_index.rb
@@ -14,7 +14,7 @@ class IndexPage < LocalPage
def _metadata
if @metadata.nil?
- yamlfile = _infile+"/index.yaml"
+ yamlfile = local_infile+"/index.yaml"
if File::exist?(yamlfile)
@metadata = YAML::load(File::read(yamlfile))
else
@@ -24,19 +24,19 @@ class IndexPage < LocalPage
@metadata
end
def _ls
- @ls ||= Dir::entries(_infile)
+ @ls ||= Dir::entries(local_infile)
.select{|fname|not fname.start_with?(".")}
- .map{|fname|"#{_infile}/#{fname}"}
+ .map{|fname|"#{local_infile}/#{fname}"}
.select{|path|Dir::exist?(path) or Config::get.html_suffixes.include?(File::extname(path).gsub(/^[.]/, ''))}
end
- def pages
+ def index_pages
if @pages.nil?
@pages = []
for path in _ls
if Dir::exist?(path)
page = IndexPage::new(path)
@pages.unshift(page)
- @pages += page.pages
+ @pages += page.index_pages
else
@pages.unshift(LocalPage::new(path))
end
@@ -48,16 +48,43 @@ class IndexPage < LocalPage
@pages
end
- def _published
+ def atom_title
+ _metadata['title']
+ end
+
+ def local_outfile
+ local_infile.sub(/^src/, 'out')+"/index.html"
+ end
+ def local_depends
+ if @depends.nil?
+ basename = local_infile.sub(/^src/, 'out')
+ deps = Set[local_infile]
+ yamlfile = local_infile+"/index.yaml"
+ if File::exist?(yamlfile)
+ deps.add(yamlfile)
+ end
+ index_pages.each{|p|deps.merge(p.local_outfile[''])}
+ @depends = {
+ "#{basename}/index.html" => deps.clone.merge(["tmpl/index.md.erb", "tmpl/page.html.erb"]),
+ "#{basename}/index.atom" => deps.clone.merge(["tmpl/index.atom.erb", "tmpl/page.atom.erb"]),
+ }
+ end
+ @depends
+ end
+ def local_srcurl
+ return nil
+ end
+
+ def page_published
return nil
end
- def _updated
+ def page_updated
return nil
end
- def _years
+ def page_years
return Set[]
end
end
ERB::new(File::read("tmpl/index.atom.erb")).def_method(IndexPage, 'atom()', "tmpl/index.atom.erb")
-ERB::new(File::read("tmpl/index.md.erb")).def_method(IndexPage, '_input()', "tmpl/index.md.erb")
+ERB::new(File::read("tmpl/index.md.erb")).def_method(IndexPage, 'local_input()', "tmpl/index.md.erb")
diff --git a/lib/page_local.rb b/lib/page_local.rb
index 1ca14f0..5b2af3b 100644
--- a/lib/page_local.rb
+++ b/lib/page_local.rb
@@ -17,34 +17,34 @@ class LocalPage < Page
# Some of this code looks a little weird because it is
# super-aggressively lazy-evaluated and cached.
- def _infile ; @infile ; end
- def _input ; @input ||= File::read(_infile) ; end
+ def local_infile ; @infile ; end
+ def local_input ; @input ||= File::read(local_infile); end
def _pandoc
if @pandoc.nil?
types = {
'md' => 'markdown'
}
- ext = File::extname(_infile).gsub(/^[.]/, '')
+ ext = File::extname(local_infile).gsub(/^[.]/, '')
type = types[ext] || ext
- @pandoc = Pandoc::load(type, _input)
+ @pandoc = Pandoc::load(type, local_input)
if @pandoc['pandoc_format']
- @pandoc = Pandoc::load(@pandoc['pandoc_format'], _input)
+ @pandoc = Pandoc::load(@pandoc['pandoc_format'], local_input)
end
end
@pandoc
end
# Query simple document metadata
- def title ; @title ||= _pandoc['title'] || _input.split("\n",2).first ; end
- def author ; @author ||= Person::new( _pandoc['author'] || Config::get.default_author) ; end
- def license ; @license ||= License::new(_pandoc['license'] || Config::get.default_license); end
- def head ; @head ||= _pandoc['html_head_extra'] ; end
- def class ; @class ||= _pandoc['class'] ; end
- def _tags ; @_tags ||= _pandoc['tags'] || [] ; end
-
- def content
+ def atom_author ; @author ||= Person::new( _pandoc['author'] || Config::get.default_author) ; end
+ def atom_title ; @title ||= _pandoc['title'] || local_input.split("\n",2).first ; end
+ def html_class ; @class ||= _pandoc['class'] ; end
+ def html_head_extra ; @head ||= _pandoc['html_head_extra'] ; end
+ def local_license ; @license ||= License::new(_pandoc['license'] || Config::get.default_license); end
+ def page_categories ; @cats ||= _pandoc['categories'] || [] ; end
+
+ def atom_content
if @content.nil?
@content = ''
# Only insert the title if it came from Pandoc metadata;
@@ -60,17 +60,17 @@ class LocalPage < Page
@content
end
- def rights
+ def atom_rights
# TODO: simplify year spans
- @rights ||= "<p>The content of this page is Copyright © #{years.sort.join(', ')} #{author.html}.</p>\n" +
- "<p>This page is licensed under the #{license.html} license.</p>"
+ @rights ||= "<p>The content of this page is Copyright © #{years.sort.join(', ')} #{atom_author.html}.</p>\n" +
+ "<p>This page is licensed under the #{local_license.html} license.</p>"
end
def _gitdates
- @gitdates ||= `git log --format='%cI' -- #{_infile}`.split('\n').select{|s|!s.empty?}.map{|s|DateTime::iso8601(s)}
+ @gitdates ||= `git log --format='%cI' -- #{local_infile}`.split("\n").select{|s|!s.empty?}.map{|s|DateTime::iso8601(s)}
end
- def _published
+ def page_published
if @_published.nil?
raw = _pandoc['published']
@_published = Datetime::parse(raw) unless raw.nil?
@@ -81,7 +81,7 @@ class LocalPage < Page
@_published
end
- def _updated
+ def page_updated
if @_updated.nil?
raw = _pandoc['updated']
@_updated = DateTime::parse(raw) unless raw.nil?
@@ -91,24 +91,32 @@ class LocalPage < Page
end
@_updated
end
-
- def _years
- @years ||= Set[*_gitdates.map{|dt|dt.year}]
+
+ def page_years
+ @years ||= Set[*_gitdates.map{|dt|dt.year}]
end
- def abssrcpath
- @srcpath ||= _infile.sub(/^(src|out)\//, '/')
+ def local_outfile
+ local_infile.sub(/^src/, 'out').sub(/\.[^\/.]*$/, '.html')
end
- def absoutpath
- @outpath ||= abssrcpath.sub(/\.[^\/.]*$/, '.html').sub(/\/index[.]html$/, '')
+ def local_depends
+ if @depends.nil?
+ basename = local_infile.sub(/^src/, 'out').sub(/\.[^\/.]*$/, '')
+ @depends = {
+ "#{basename}.html" => Set[local_infile, "tmpl/page.html.erb"],
+ #"#{basename}.atom" => Set[local_infile, "tmpl/page.atom.erb"]
+ }
+ end
+ @depends
end
- def url
- @url ||= Config::get.url + absoutpath
+ def local_srcurl
+ @srcurl ||= Config::get.url + local_infile.sub(/^src/, '')
end
- def srcurl
- @srcurl ||= Config::get.url + abssrcpath
+ def url
+ @outurl ||= Config::get.url + local_outfile.sub(/^out/, '')
end
end
+ERB::new(File::read("tmpl/page.atom.erb")).def_method(LocalPage, 'atom()', "tmpl/page.atom.erb")
ERB::new(File::read("tmpl/page.html.erb")).def_method(LocalPage, 'html()', "tmpl/page.html.erb")
diff --git a/lib/page_remote.rb b/lib/page_remote.rb
index a754af6..e886283 100644
--- a/lib/page_remote.rb
+++ b/lib/page_remote.rb
@@ -3,7 +3,6 @@ require 'date'
require 'config'
require 'page'
-require 'tag'
class RemotePage < Page
def initialize(metadata)
@@ -14,27 +13,27 @@ class RemotePage < Page
return Config::get.url + @metadata['url']
end
- def title
+ def atom_title
@metadata['title']
end
- def author
+ def atom_author
Person::new(@metadata['author'] || Config::get.default_author)
end
- def content
+ def atom_content
return nil
end
- def rights
+ def atom_rights
return nil
end
- def _tags
- @metadata['tags'] || []
+ def page_cagetories
+ @metadata['categories'] || []
end
- def _published
+ def page_published
str = @metadata['published']
if str.nil?
return nil
@@ -42,7 +41,7 @@ class RemotePage < Page
return Date::parse(str)
end
- def _updated
+ def page_updated
str = @metadata['updated']
if str.nil?
return nil
@@ -50,7 +49,7 @@ class RemotePage < Page
return Date::parse(str)
end
- def _years
+ def page_years
return []
end
end