hobber 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rvmrc +1 -0
- data/Gemfile +16 -0
- data/LICENSE +22 -0
- data/README.md +50 -0
- data/Rakefile +2 -0
- data/hobber.gemspec +17 -0
- data/lib/hobber/render_action.rb +76 -0
- data/lib/hobber/renderable_object.rb +65 -0
- data/lib/hobber/rendered_object.rb +13 -0
- data/lib/hobber/rendered_object_saver.rb +30 -0
- data/lib/hobber/version.rb +3 -0
- data/lib/hobber.rb +56 -0
- data/spec/integration_spec.rb +72 -0
- data/spec/lib/hobber/render_action_spec.rb +63 -0
- data/spec/lib/hobber/renderable_object_spec.rb +108 -0
- data/spec/lib/hobber/rendered_object_saver_spec.rb +8 -0
- data/spec/lib/hobber/rendered_object_spec.rb +16 -0
- data/spec/lib/hobber_spec.rb +14 -0
- data/spec/miniblog/source/index.haml +6 -0
- data/spec/miniblog/source/layout/index.haml +11 -0
- data/spec/miniblog/source/layout/main.haml +8 -0
- data/spec/miniblog/source/layout/post.haml +7 -0
- data/spec/miniblog/source/posts/2012-01-01-post001.mkd.erb +5 -0
- data/spec/miniblog/source/posts/2012-01-01-post002.mkd +1 -0
- data/spec/miniblog/source/posts/2012-01-01-post003.haml +2 -0
- data/spec/miniblog/source/posts/2012-01-01-post004.html +1 -0
- data/spec/source/posts/2012-01-01-post001.mkd +2 -0
- data/spec/source/posts/2012-01-01-post001.mkd.erb +1 -0
- data/spec/source/posts/2012-01-01-post002.html +1 -0
- metadata +92 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
rvm use 1.9.2@hobber --create
|
data/Gemfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
source 'https://rubygems.org'
|
2
|
+
|
3
|
+
gem 'tilt'
|
4
|
+
gem 'rdiscount'
|
5
|
+
gem 'contracts'
|
6
|
+
gem 'haml'
|
7
|
+
gem 'thor'
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem 'pry'
|
11
|
+
gem 'rspec'
|
12
|
+
gem 'ruby-debug19'
|
13
|
+
end
|
14
|
+
|
15
|
+
# Specify your gem's dependencies in hobber.gemspec
|
16
|
+
gemspec
|
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Boy Maas
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
# Hobber
|
2
|
+
|
3
|
+
A minimalistic static blogging engine
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'hobber'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install hobber
|
18
|
+
|
19
|
+
## Philosophy
|
20
|
+
|
21
|
+
Files are objects, objects can be composed and accessed.
|
22
|
+
Files can be scanned, inside, directories and can be filtered.
|
23
|
+
|
24
|
+
## Usage
|
25
|
+
|
26
|
+
blog_posts = scan 'source/posts/**/*'
|
27
|
+
index_page = file 'source/index'
|
28
|
+
main_layout = file 'source/layout'
|
29
|
+
blog_layout = file 'source/posts/layout'
|
30
|
+
|
31
|
+
render blog_posts, :layout => blog_layout, :to => 'output/posts/'
|
32
|
+
|
33
|
+
rendered_blog_posts = render blog_posts do
|
34
|
+
layout blog_layout
|
35
|
+
rewrite_path %r|^source|, 'output'
|
36
|
+
end
|
37
|
+
|
38
|
+
rendered_home_page = render index_page do
|
39
|
+
layout main_layout
|
40
|
+
rewrite_path %r|^source|, 'output'
|
41
|
+
tmpl_vars :blog_posts => rendered_blog_posts
|
42
|
+
end
|
43
|
+
|
44
|
+
## Contributing
|
45
|
+
|
46
|
+
1. Fork it
|
47
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
48
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
49
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
50
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/hobber.gemspec
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/hobber/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Boy Maas"]
|
6
|
+
gem.email = ["boy.maas@gmail.com"]
|
7
|
+
gem.description = %q{Minimal implementation ..}
|
8
|
+
gem.summary = %q{Minimal implementation ..}
|
9
|
+
gem.homepage = "http://www.github.com/boymaas/Hobber"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
14
|
+
gem.name = "hobber"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = Hobber::VERSION
|
17
|
+
end
|
@@ -0,0 +1,76 @@
|
|
1
|
+
require 'hobber/renderable_object'
|
2
|
+
require 'hobber/rendered_object'
|
3
|
+
|
4
|
+
module Hobber
|
5
|
+
class RenderAction
|
6
|
+
def initialize robjects, &block
|
7
|
+
@robjects = robjects
|
8
|
+
@tmpl_vars = {}
|
9
|
+
@layouts = []
|
10
|
+
@rewrite_paths = []
|
11
|
+
@target_extention = nil
|
12
|
+
|
13
|
+
if block
|
14
|
+
block.arity <= 0 ? instance_eval(&block) : block.call(self)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def layout robject
|
19
|
+
raise ArgumentError.new('Expected RenderableObject as a layout') unless robject.is_a?(RenderableObject)
|
20
|
+
@layouts << robject
|
21
|
+
end
|
22
|
+
|
23
|
+
def tmpl_vars vars
|
24
|
+
@tmpl_vars.merge!(vars)
|
25
|
+
end
|
26
|
+
|
27
|
+
def rewrite_path regexp, replacement
|
28
|
+
@rewrite_paths << [regexp, replacement]
|
29
|
+
end
|
30
|
+
|
31
|
+
def target_extention ext
|
32
|
+
@target_extention = ext.to_s
|
33
|
+
end
|
34
|
+
|
35
|
+
# Performs the render actions by
|
36
|
+
# iterating over robjects with
|
37
|
+
# the specified configuration
|
38
|
+
def perform
|
39
|
+
@robjects.map do |ro|
|
40
|
+
RenderedObject.new(
|
41
|
+
:data=>render_renderable_object(ro, @tmpl_vars, @layouts),
|
42
|
+
:renderable_object=>ro,
|
43
|
+
:layouts=> @layouts,
|
44
|
+
:path=>rewrite_paths(ro.path, @rewrite_paths))
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
protected
|
49
|
+
|
50
|
+
def render_renderable_object ro, tmpl_vars={}, layouts=[]
|
51
|
+
tmpl_vars.merge!(ro.tmpl_vars)
|
52
|
+
|
53
|
+
result = ro.render(tmpl_vars)
|
54
|
+
|
55
|
+
render_chain = layouts.reverse
|
56
|
+
render_chain.each do |layout|
|
57
|
+
tmpl_vars = layout.tmpl_vars.merge(tmpl_vars)
|
58
|
+
result = layout.render(tmpl_vars) { result }
|
59
|
+
end
|
60
|
+
result
|
61
|
+
end
|
62
|
+
|
63
|
+
def rewrite_paths path, rewrites
|
64
|
+
target_path = path.dup
|
65
|
+
rewrites.each do |regexp, replacement|
|
66
|
+
target_path.gsub!(regexp, replacement)
|
67
|
+
end
|
68
|
+
|
69
|
+
if @target_extention
|
70
|
+
target_path.gsub!(/\..*?$/, ".#{@target_extention}")
|
71
|
+
end
|
72
|
+
|
73
|
+
target_path
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require 'tilt'
|
2
|
+
require 'yaml'
|
3
|
+
|
4
|
+
module Hobber
|
5
|
+
class ProblemParsingYaml < RuntimeError; end
|
6
|
+
class RenderableObject
|
7
|
+
attr_reader :path, :data
|
8
|
+
|
9
|
+
def initialize(path)
|
10
|
+
@path = path
|
11
|
+
@data = yield(self) if block_given?
|
12
|
+
end
|
13
|
+
|
14
|
+
def render(vars={}, &block)
|
15
|
+
context = Object.new
|
16
|
+
_render_template_chain(@path, data, context, vars, &block)
|
17
|
+
end
|
18
|
+
|
19
|
+
def to_a
|
20
|
+
[self]
|
21
|
+
end
|
22
|
+
|
23
|
+
def data
|
24
|
+
@data ||= File.read(@path)
|
25
|
+
end
|
26
|
+
|
27
|
+
def tmpl_vars
|
28
|
+
@tmpl_vars ||= _extract_tmpl_vars
|
29
|
+
end
|
30
|
+
def _extract_tmpl_vars
|
31
|
+
@tmpl_vars = {}
|
32
|
+
if data.match(/\s*---.*---/m)
|
33
|
+
ignore, yaml_buffer, template_data = data.split(/---/,3)
|
34
|
+
@data = template_data
|
35
|
+
@tmpl_vars = YAML.parse(yaml_buffer).to_ruby
|
36
|
+
end
|
37
|
+
@tmpl_vars
|
38
|
+
rescue Psych::SyntaxError => e
|
39
|
+
raise ProblemParsingYaml.new([e.message, "while trying to extract tmpl_vars from [#{path}]"] * " -- ")
|
40
|
+
end
|
41
|
+
|
42
|
+
private
|
43
|
+
|
44
|
+
def _render_template_chain(path, data, context, vars, &block)
|
45
|
+
# termination condition, if tilt template class
|
46
|
+
# is
|
47
|
+
tilt_template_class = Tilt[path]
|
48
|
+
unless tilt_template_class
|
49
|
+
return data
|
50
|
+
end
|
51
|
+
|
52
|
+
template = tilt_template_class.new(@path) { |t| data }
|
53
|
+
|
54
|
+
# remove extention
|
55
|
+
path = path.gsub(/\.\w+$/,'')
|
56
|
+
data = template.render(context, vars, &block)
|
57
|
+
|
58
|
+
# iterate again to next available template
|
59
|
+
# engine
|
60
|
+
_render_template_chain(path, data, context, vars, &block)
|
61
|
+
rescue => e
|
62
|
+
raise "#{self.class}: While rendering #{path} with #{tilt_template_class}: #{e.message}"
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Hobber
|
2
|
+
class RenderedObject
|
3
|
+
attr_reader :data, :path
|
4
|
+
|
5
|
+
def initialize opts={}
|
6
|
+
@data = opts.fetch(:data)
|
7
|
+
@renderable_object = opts.fetch(:renderable_object)
|
8
|
+
@path = opts.fetch(:path)
|
9
|
+
@layouts = opts.fetch(:layouts)
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'thor'
|
2
|
+
require 'fileutils'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
module Hobber
|
6
|
+
class RenderedObjectSaver
|
7
|
+
include FileUtils
|
8
|
+
include Thor::Shell
|
9
|
+
|
10
|
+
def initialize(rendered_object, safe_mode=false, logger=Logger.new(STDOUT))
|
11
|
+
@rendered_object = rendered_object
|
12
|
+
@safe_mode = safe_mode
|
13
|
+
@logger = logger
|
14
|
+
end
|
15
|
+
|
16
|
+
def save
|
17
|
+
path_name = Pathname.new(@rendered_object.path)
|
18
|
+
if @safe_mode && path_name.exist? && !file_collision(path_name)
|
19
|
+
return
|
20
|
+
end
|
21
|
+
|
22
|
+
mkdir_p(path_name.dirname)
|
23
|
+
|
24
|
+
@logger.info("writing target [#{path_name}] ..")
|
25
|
+
File.open(@rendered_object.path, 'w') do |f|
|
26
|
+
f.write(@rendered_object.data)
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/hobber.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'fileutils'
|
2
|
+
require 'thor'
|
3
|
+
require 'logger'
|
4
|
+
|
5
|
+
require "hobber/version"
|
6
|
+
require 'hobber/renderable_object'
|
7
|
+
require 'hobber/rendered_object_saver'
|
8
|
+
require 'hobber/render_action'
|
9
|
+
|
10
|
+
module Hobber
|
11
|
+
class Shell
|
12
|
+
include Thor::Shell
|
13
|
+
end
|
14
|
+
|
15
|
+
def shell
|
16
|
+
@shell ||= Shell.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def remove_output_dir dirname, options={}
|
20
|
+
safe_mode = options.fetch(:safe, false)
|
21
|
+
|
22
|
+
dirname = Pathname.new(dirname)
|
23
|
+
if safe_mode && shell.no?("Do you want to remove output dir [#{dirname.realpath}]? (y/yes/other=no)")
|
24
|
+
return
|
25
|
+
end
|
26
|
+
FileUtils.rm_r dirname.realpath
|
27
|
+
rescue Errno::ENOENT
|
28
|
+
# directory does not resolve
|
29
|
+
end
|
30
|
+
|
31
|
+
def chdir path, &block
|
32
|
+
Dir.chdir(path, &block)
|
33
|
+
end
|
34
|
+
|
35
|
+
def scan glob
|
36
|
+
Dir[glob].map { |p| RenderableObject.new(p) }
|
37
|
+
end
|
38
|
+
|
39
|
+
def file path
|
40
|
+
RenderableObject.new(path)
|
41
|
+
end
|
42
|
+
|
43
|
+
def render robjects, opts={}, &block
|
44
|
+
rv = RenderAction.new(robjects.to_a, &block).perform
|
45
|
+
robjects.is_a?(Array) ? rv : rv.first
|
46
|
+
end
|
47
|
+
|
48
|
+
def save *args
|
49
|
+
options = args.last.is_a?(Hash) ? args.pop : {}
|
50
|
+
logger = options.fetch(:logger, Logger.new(STDOUT))
|
51
|
+
safe_mode = options.fetch(:safe, false)
|
52
|
+
args.flatten.map { |rendered_object|
|
53
|
+
RenderedObjectSaver.new(rendered_object, safe_mode, logger).save
|
54
|
+
}
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'hobber'
|
2
|
+
|
3
|
+
describe "hobber renders a blog" do
|
4
|
+
before { extend Hobber }
|
5
|
+
before { chdir 'spec/miniblog' }
|
6
|
+
after { chdir '../..' }
|
7
|
+
|
8
|
+
let(:shell) { stub(:shell) }
|
9
|
+
|
10
|
+
before do
|
11
|
+
Hobber.stub(:shell => shell)
|
12
|
+
shell.stub(:yes?).and_return(true)
|
13
|
+
|
14
|
+
remove_output_dir 'output'
|
15
|
+
|
16
|
+
blog_posts = scan 'source/posts/**/*'
|
17
|
+
index_page = file 'source/index.haml'
|
18
|
+
main_layout = file 'source/layout/main.haml'
|
19
|
+
index_layout = file 'source/layout/index.haml'
|
20
|
+
post_layout = file 'source/layout/post.haml'
|
21
|
+
|
22
|
+
rendered_blog_posts = render blog_posts do
|
23
|
+
layout main_layout
|
24
|
+
layout post_layout
|
25
|
+
rewrite_path %r|^source|, 'output'
|
26
|
+
target_extention :html
|
27
|
+
end
|
28
|
+
|
29
|
+
rendered_home_page = render index_page do
|
30
|
+
layout main_layout
|
31
|
+
layout index_layout
|
32
|
+
rewrite_path %r|^source|, 'output'
|
33
|
+
tmpl_vars :blog_posts => rendered_blog_posts
|
34
|
+
target_extention :html
|
35
|
+
end
|
36
|
+
|
37
|
+
@rendered_blog_posts = rendered_blog_posts
|
38
|
+
@rendered_home_page = rendered_home_page
|
39
|
+
|
40
|
+
save [rendered_home_page, rendered_blog_posts], :logger => stub(:logger).as_null_object
|
41
|
+
end
|
42
|
+
|
43
|
+
it "renders 4 blog posts" do
|
44
|
+
@rendered_blog_posts.should be_an(Array)
|
45
|
+
@rendered_blog_posts.count.should == 4
|
46
|
+
end
|
47
|
+
|
48
|
+
it "first blogpost has correct content" do
|
49
|
+
first_blog_post = @rendered_blog_posts.first
|
50
|
+
first_blog_post.data.should include('html')
|
51
|
+
first_blog_post.data.should include('body')
|
52
|
+
first_blog_post.data.should include('Title post 001')
|
53
|
+
first_blog_post.data.should include('Post layout')
|
54
|
+
first_blog_post.data.should include('Post footer')
|
55
|
+
end
|
56
|
+
|
57
|
+
it "returns rendered_home_page as a rendered object" do
|
58
|
+
@rendered_home_page.should be_an(RenderedObject)
|
59
|
+
@rendered_home_page.data.should include('html')
|
60
|
+
@rendered_home_page.data.should include('body')
|
61
|
+
@rendered_home_page.data.should include('This is the index of a blog')
|
62
|
+
@rendered_home_page.data.should include('Content index haml')
|
63
|
+
@rendered_home_page.data.should include('post001.html')
|
64
|
+
@rendered_home_page.data.should include('post002.html')
|
65
|
+
@rendered_home_page.data.should include('post003.html')
|
66
|
+
@rendered_home_page.data.should include('post004.html')
|
67
|
+
end
|
68
|
+
|
69
|
+
it "rendered all files" do
|
70
|
+
Dir['output/**/*.html'].count.should == 5
|
71
|
+
end
|
72
|
+
end
|
@@ -0,0 +1,63 @@
|
|
1
|
+
require 'hobber/renderable_object'
|
2
|
+
require 'hobber/render_action'
|
3
|
+
|
4
|
+
module Hobber
|
5
|
+
describe RenderAction do
|
6
|
+
subject {described_class.new([])}
|
7
|
+
context "#layout" do
|
8
|
+
it "adds a layout" do
|
9
|
+
robject = RenderableObject.new('a_path')
|
10
|
+
subject.layout robject
|
11
|
+
end
|
12
|
+
it "raises when adding something other than RenderableObject" do
|
13
|
+
expect {
|
14
|
+
subject.layout Object.new
|
15
|
+
}.to raise_error(ArgumentError)
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
context "#perform" do
|
20
|
+
let(:layout) do RenderableObject.new('source_path/to/layout.mkd.erb') do
|
21
|
+
<<-EOS.gsub(/^\s{10}/, '')
|
22
|
+
---
|
23
|
+
title: a title
|
24
|
+
---
|
25
|
+
# Title: <%= title %>
|
26
|
+
|
27
|
+
<%= yield %>
|
28
|
+
EOS
|
29
|
+
end
|
30
|
+
end
|
31
|
+
let(:content) do RenderableObject.new('source_path/to/content.txt') do
|
32
|
+
<<-EOS.gsub(/^\s{10}/, '')
|
33
|
+
---
|
34
|
+
title: a overridden title
|
35
|
+
---
|
36
|
+
just some content
|
37
|
+
EOS
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "overrides and renders layout and content templates" do
|
42
|
+
render_action = RenderAction.new([content])
|
43
|
+
render_action.layout(layout)
|
44
|
+
|
45
|
+
render_action.rewrite_path(/^source_path/, 'inter_path')
|
46
|
+
render_action.rewrite_path(/^inter_path/, 'target_path')
|
47
|
+
render_action.target_extention(:html)
|
48
|
+
|
49
|
+
array_of_rendered_objects = render_action.perform
|
50
|
+
array_of_rendered_objects.should be_an(Array)
|
51
|
+
|
52
|
+
rendered_object = array_of_rendered_objects.first
|
53
|
+
rendered_object.should be_an(RenderedObject)
|
54
|
+
rendered_object.data.should == <<-EOS.gsub(/^\s{10}/, '')
|
55
|
+
<h1>Title: a overridden title</h1>
|
56
|
+
|
57
|
+
<p>just some content</p>
|
58
|
+
EOS
|
59
|
+
rendered_object.path.should == 'target_path/to/content.html'
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
end
|
@@ -0,0 +1,108 @@
|
|
1
|
+
require 'hobber/renderable_object'
|
2
|
+
|
3
|
+
module Hobber
|
4
|
+
describe RenderableObject do
|
5
|
+
context "plain html" do
|
6
|
+
subject { described_class.new('spec/source/posts/2012-01-01-post002.html') }
|
7
|
+
it "renders" do
|
8
|
+
subject.render.should include('<h1>Post002</h1>')
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
context "markdown" do
|
13
|
+
subject { described_class.new('spec/source/posts/2012-01-01-post001.mkd') }
|
14
|
+
|
15
|
+
it "renders" do
|
16
|
+
subject.render.should include('<h1>Title</h1>')
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
context "erb markdown" do
|
21
|
+
subject { described_class.new('spec/source/posts/2012-01-01-post001.mkd.erb') }
|
22
|
+
it "renders" do
|
23
|
+
subject.render(:a_var=>:for_example).should include('<h1>Title for_example</h1>')
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
context "#tmpl_vars" do
|
28
|
+
context "whithout tmpl_vars specified" do
|
29
|
+
subject { described_class.new('spec/source/posts/2012-01-01-post001.mkd') }
|
30
|
+
it "now just returns an empty hash" do
|
31
|
+
subject.tmpl_vars.should == {}
|
32
|
+
end
|
33
|
+
end
|
34
|
+
context "with one tmpl_vars specified" do
|
35
|
+
subject do
|
36
|
+
described_class.new('path_to_template.mkd') {
|
37
|
+
<<-EOS.gsub(/^\s{12}/, '')
|
38
|
+
---
|
39
|
+
title: a title
|
40
|
+
---
|
41
|
+
|
42
|
+
# Title
|
43
|
+
EOS
|
44
|
+
}
|
45
|
+
end
|
46
|
+
it "returns the template vars" do
|
47
|
+
subject.tmpl_vars.should == {
|
48
|
+
'title' => 'a title',
|
49
|
+
}
|
50
|
+
end
|
51
|
+
end
|
52
|
+
context "with tmpl_vars specified" do
|
53
|
+
subject do
|
54
|
+
described_class.new('path_to_template.mkd') {
|
55
|
+
<<-EOS.gsub(/^\s{12}/, '')
|
56
|
+
---
|
57
|
+
title: a title
|
58
|
+
author: a author
|
59
|
+
tags:
|
60
|
+
- tag1
|
61
|
+
- tag2
|
62
|
+
- tag3
|
63
|
+
---
|
64
|
+
|
65
|
+
# Title
|
66
|
+
|
67
|
+
EOS
|
68
|
+
}
|
69
|
+
end
|
70
|
+
it "returns the template vars" do
|
71
|
+
subject.tmpl_vars.should == {
|
72
|
+
'title' => 'a title',
|
73
|
+
'author' => 'a author',
|
74
|
+
'tags' => ['tag1', 'tag2', 'tag3']
|
75
|
+
}
|
76
|
+
end
|
77
|
+
end
|
78
|
+
context "with incorrect yaml specified" do
|
79
|
+
subject do
|
80
|
+
described_class.new('path_to_template.mkd') {
|
81
|
+
<<-EOS.gsub(/^\s{12}/, '')
|
82
|
+
---
|
83
|
+
title: a title
|
84
|
+
author: a author
|
85
|
+
wong-yaml-stuff-in-here
|
86
|
+
tags:
|
87
|
+
- tag1
|
88
|
+
- tag2
|
89
|
+
- tag3
|
90
|
+
---
|
91
|
+
|
92
|
+
# Title
|
93
|
+
|
94
|
+
EOS
|
95
|
+
}
|
96
|
+
end
|
97
|
+
it "raises an appropiate error" do
|
98
|
+
expect {
|
99
|
+
subject.tmpl_vars
|
100
|
+
}.to raise_error {|e|
|
101
|
+
e.should be_an(ProblemParsingYaml)
|
102
|
+
e.message.should include("path_to_template.mkd")
|
103
|
+
}
|
104
|
+
end
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end
|
108
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'hobber/rendered_object'
|
2
|
+
|
3
|
+
module Hobber
|
4
|
+
describe RenderedObject do
|
5
|
+
context "#initialize" do
|
6
|
+
it "works" do
|
7
|
+
described_class.new(
|
8
|
+
:data=>:data,
|
9
|
+
:renderable_object=>:renderable_object,
|
10
|
+
:path=>:path,
|
11
|
+
:layouts=>:layouts
|
12
|
+
)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'hobber'
|
2
|
+
|
3
|
+
describe Hobber do
|
4
|
+
before { extend Hobber }
|
5
|
+
|
6
|
+
context "#scan" do
|
7
|
+
let(:robjects) { scan "spec/source/posts/*" }
|
8
|
+
context "when dir is full" do
|
9
|
+
specify { robjects.should be_an(Array) }
|
10
|
+
specify { robjects.first.should be_an(RenderableObject) }
|
11
|
+
specify { robjects.first.path.should == 'spec/source/posts/2012-01-01-post001.mkd' }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
## Post002
|
@@ -0,0 +1 @@
|
|
1
|
+
<h2>Post004</h2>
|
@@ -0,0 +1 @@
|
|
1
|
+
# Title <%= a_var %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<h1>Post002</h1>
|
metadata
ADDED
@@ -0,0 +1,92 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: hobber
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.5.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Boy Maas
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-06-26 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Minimal implementation ..
|
15
|
+
email:
|
16
|
+
- boy.maas@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rvmrc
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- hobber.gemspec
|
28
|
+
- lib/hobber.rb
|
29
|
+
- lib/hobber/render_action.rb
|
30
|
+
- lib/hobber/renderable_object.rb
|
31
|
+
- lib/hobber/rendered_object.rb
|
32
|
+
- lib/hobber/rendered_object_saver.rb
|
33
|
+
- lib/hobber/version.rb
|
34
|
+
- spec/integration_spec.rb
|
35
|
+
- spec/lib/hobber/render_action_spec.rb
|
36
|
+
- spec/lib/hobber/renderable_object_spec.rb
|
37
|
+
- spec/lib/hobber/rendered_object_saver_spec.rb
|
38
|
+
- spec/lib/hobber/rendered_object_spec.rb
|
39
|
+
- spec/lib/hobber_spec.rb
|
40
|
+
- spec/miniblog/source/index.haml
|
41
|
+
- spec/miniblog/source/layout/index.haml
|
42
|
+
- spec/miniblog/source/layout/main.haml
|
43
|
+
- spec/miniblog/source/layout/post.haml
|
44
|
+
- spec/miniblog/source/posts/2012-01-01-post001.mkd.erb
|
45
|
+
- spec/miniblog/source/posts/2012-01-01-post002.mkd
|
46
|
+
- spec/miniblog/source/posts/2012-01-01-post003.haml
|
47
|
+
- spec/miniblog/source/posts/2012-01-01-post004.html
|
48
|
+
- spec/source/posts/2012-01-01-post001.mkd
|
49
|
+
- spec/source/posts/2012-01-01-post001.mkd.erb
|
50
|
+
- spec/source/posts/2012-01-01-post002.html
|
51
|
+
homepage: http://www.github.com/boymaas/Hobber
|
52
|
+
licenses: []
|
53
|
+
post_install_message:
|
54
|
+
rdoc_options: []
|
55
|
+
require_paths:
|
56
|
+
- lib
|
57
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ! '>='
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
version: '0'
|
63
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
64
|
+
none: false
|
65
|
+
requirements:
|
66
|
+
- - ! '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
requirements: []
|
70
|
+
rubyforge_project:
|
71
|
+
rubygems_version: 1.8.24
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Minimal implementation ..
|
75
|
+
test_files:
|
76
|
+
- spec/integration_spec.rb
|
77
|
+
- spec/lib/hobber/render_action_spec.rb
|
78
|
+
- spec/lib/hobber/renderable_object_spec.rb
|
79
|
+
- spec/lib/hobber/rendered_object_saver_spec.rb
|
80
|
+
- spec/lib/hobber/rendered_object_spec.rb
|
81
|
+
- spec/lib/hobber_spec.rb
|
82
|
+
- spec/miniblog/source/index.haml
|
83
|
+
- spec/miniblog/source/layout/index.haml
|
84
|
+
- spec/miniblog/source/layout/main.haml
|
85
|
+
- spec/miniblog/source/layout/post.haml
|
86
|
+
- spec/miniblog/source/posts/2012-01-01-post001.mkd.erb
|
87
|
+
- spec/miniblog/source/posts/2012-01-01-post002.mkd
|
88
|
+
- spec/miniblog/source/posts/2012-01-01-post003.haml
|
89
|
+
- spec/miniblog/source/posts/2012-01-01-post004.html
|
90
|
+
- spec/source/posts/2012-01-01-post001.mkd
|
91
|
+
- spec/source/posts/2012-01-01-post001.mkd.erb
|
92
|
+
- spec/source/posts/2012-01-01-post002.html
|