summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuke Shumaker <lukeshu@sbcglobal.net>2016-09-03 16:28:56 -0400
committerLuke Shumaker <lukeshu@sbcglobal.net>2016-09-03 16:28:58 -0400
commit0d05aa02b65941586a22f283a9c0f617f0314d0f (patch)
treed64b0d0caaaa30318e5c3eaa87526b4930cae31e
parent132323501850eec21c1ccfd00b654428d8bafe53 (diff)
parent6f7d74f8a0c5a77441b34e3b42950c18127da3d7 (diff)
make: improve
Lazy load everything in the Page class.
-rw-r--r--.gitignore2
-rwxr-xr-xpost-commit2
-rw-r--r--util.rb54
3 files changed, 35 insertions, 23 deletions
diff --git a/.gitignore b/.gitignore
index 0fe67f8..6db2345 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,2 +1,2 @@
/.var*
-/.tmp*
+.tmp*
diff --git a/post-commit b/post-commit
index 574f468..09d2f7f 100755
--- a/post-commit
+++ b/post-commit
@@ -4,7 +4,7 @@ branch=$(git name-rev --name-only HEAD)
if [[ $branch == master ]]; then
git checkout pre-generated
git merge master -m 'bogus'
- make
+ make --always-make -j12
git add .
git commit --amend -m "make: $(git log -n1 master --pretty=format:%B)"
git checkout master
diff --git a/util.rb b/util.rb
index e50406a..160a74d 100644
--- a/util.rb
+++ b/util.rb
@@ -60,33 +60,45 @@ class License
end
class Page
- attr_accessor :title, :author, :gitdate, :date, :license, :slug, :content, :rights, :breadcrumbs
def initialize(infile)
- input = File.read(infile)
- doc = Pandoc::load('markdown', input)
+ @infile = infile
+ end
- if doc['markdown_options']
- doc = Pandoc::load('markdown'+doc['markdown_options'], input)
- end
+ def infile ; @infile ; end
+ def input ; @input ||= File.read(infile) ; end
+ def pandoc
+ if @pandoc.nil?
+ @pandoc = Pandoc::load('markdown', input)
- gitdate = `git log -n1 --format='%cI' -- #{infile}`
+ if @pandoc['markdown_options']
+ @pandoc = Pandoc::load('markdown'+@pandoc['markdown_options'], input)
+ end
+ end
+ @pandoc
+ end
- @title = doc['title'] || input.split("\n",2).first
- @author = Person.new(doc['author'] || "Luke Shumaker")
- @gitdate = DateTime.iso8601(gitdate) unless gitdate.empty?
- @date = Date.parse(doc['date']) unless doc['date'].nil?
- @license = License.new(doc['license'] || "CC BY-SA-3.0")
- @slug = infile.sub(/\..*$/,'').sub(/^.*\//,'')
- @content = doc.to('html5')
- @rights = "<p>The content of this page is Copyright © #{@date.year unless @date.nil?} #{@author.html}.</p>\n" +
- "<p>This page is licensed under the #{@license.html} license.</p>"
+ def title ; @title ||= pandoc['title'] || input.split("\n",2).first ; end
+ def author ; @author ||= Person.new( pandoc['author'] || "Luke Shumaker") ; end
+ def license ; @license ||= License.new(pandoc['license'] || "CC BY-SA-3.0") ; end
+ def date ; @date ||= Date.parse(pandoc['date']) unless pandoc['date'].nil? ; end
+ def slug ; @slug ||= infile.sub(/\..*$/,'').sub(/^.*\//,'') ; end
+ def content ; @content ||= pandoc.to('html5') ; end
- @breadcrumbs = '<a href="/">Luke Shumaker</a> » '
- if (@slug == 'index')
- @breadcrumbs += "blog"
- else
- @breadcrumbs += '<a href=/blog>blog</a> » ' + @slug
+ def gitdate
+ if @gitdate.nil?
+ raw = `git log -n1 --format='%cI' -- #{infile}`
+ @gitdate = DateTime.iso8601(raw) unless raw.empty?
end
+ @gitdate
+ end
+
+ def rights
+ @rights ||= "<p>The content of this page is Copyright © #{date.year unless date.nil?} #{author.html}.</p>\n" +
+ "<p>This page is licensed under the #{license.html} license.</p>"
+ end
+
+ def breadcrumbs
+ @breadcrumbs ||= '<a href="/">Luke Shumaker</a> » ' + ( (slug == 'index') ? "blog" : "<a href=/blog>blog</a> » #{slug}" )
end
end