From 4a3a404a5cb2a8d5be83e28cec5c539928fa30f4 Mon Sep 17 00:00:00 2001 From: Luke Shumaker Date: Fri, 6 Jan 2017 23:18:24 -0500 Subject: aaaah --- lib/page_local.rb | 68 +++++++++++++++++++++++++++++++------------------------ 1 file changed, 38 insertions(+), 30 deletions(-) (limited to 'lib/page_local.rb') 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 ||= "

The content of this page is Copyright © #{years.sort.join(', ')} #{author.html}.

\n" + - "

This page is licensed under the #{license.html} license.

" + @rights ||= "

The content of this page is Copyright © #{years.sort.join(', ')} #{atom_author.html}.

\n" + + "

This page is licensed under the #{local_license.html} license.

" 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") -- cgit v1.2.3