Class: OakTree
- Inherits:
-
Object
- Object
- OakTree
- Defined in:
- lib/oaktree.rb,
lib/oaktree/template.rb,
lib/oaktree/post_data.rb,
lib/oaktree/specification.rb,
lib/oaktree/template/base.rb,
lib/oaktree/template/blog.rb,
lib/oaktree/template/post.rb,
lib/oaktree/kramdown/oak_html.rb,
lib/oaktree/template/post_archive.rb
Overview
The central blog class (also just called a tree from time to time)
Defined Under Namespace
Modules: Kramdown, Template Classes: PostData, Specification
Constant Summary collapse
- VERSION =
'0.4.4'
- @@EMPTY_DIR_ENTRIES =
['.', '..']
Instance Method Summary collapse
- #blogspec ⇒ Object
-
#generate(force_build = false) ⇒ Object
Generates and writes the HTML files for the blog.
-
#initialize(spec) ⇒ OakTree
constructor
A new instance of OakTree.
- #posts ⇒ Object
Constructor Details
#initialize(spec) ⇒ OakTree
Returns a new instance of OakTree.
19 20 21 22 23 24 25 |
# File 'lib/oaktree.rb', line 19 def initialize spec @spec = spec @posts = [] sync_posts end |
Instance Method Details
#blogspec ⇒ Object
27 28 29 |
# File 'lib/oaktree.rb', line 27 def blogspec @spec end |
#generate(force_build = false) ⇒ Object
Generates and writes the HTML files for the blog. If force_rebuild is false, it will only rebuild pages with posts that have changed, otherwise it rebuilds everything. This does not check for changes to templates or other content – if you make any changes to templates, you must force a rebuild.
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 |
# File 'lib/oaktree.rb', line 41 def generate force_build = false blog_template = Template::Blog.new self skipped_files = [] new_files = [] updated_files = [] old_files = Dir.glob('public/**/*.html') blog_template.modes.each { |mode| blog_template.mode = mode (1..blog_template.pages).each { |page| blog_template.page = page path = blog_template.local_path pretty_path = Pathname.new(path).relative_path_from(Pathname.new(@spec.blog_root)).to_s if old_files.include? pretty_path old_files.delete pretty_path end mtime = File.exists?(path) ? File.mtime(path) : nil needs_update = force_build || mtime.nil? if ! needs_update needs_update = blog_template.posts.any? { |post| mtime < File.mtime(post.post_data.source_path) } if ! needs_update skipped_files << path next end end dir = File.dirname(path) FileUtils.mkdir_p dir unless File.directory? dir if File.exists? path updated_files << pretty_path else new_files << pretty_path end r = nil File.open(path, 'w') { |io| io.write blog_template.render } } } updated_files.each { |path| puts "* #{path}" } new_files.each { |path| puts "+ #{path}"} old_files.each { |path| puts "- #{path}" File.unlink path dir = File.dirname path if Dir.entries(dir) == @@EMPTY_DIR_ENTRIES Dir.unlink dir end } end |
#posts ⇒ Object
31 32 33 34 |
# File 'lib/oaktree.rb', line 31 def posts sync_posts return @posts end |