howl 0.4.1 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.4.1
1
+ 0.5.0
data/howl.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{howl}
8
- s.version = "0.4.1"
8
+ s.version = "0.5.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Clinton R. Nixon"]
@@ -41,6 +41,7 @@ Gem::Specification.new do |s|
41
41
  "sample_site/site/index.html",
42
42
  "sample_site/templates/default.html",
43
43
  "sample_site/templates/site.html",
44
+ "test/fixtures/config.yml",
44
45
  "test/fixtures/posts/first_post.html",
45
46
  "test/fixtures/posts/markdown_post.md",
46
47
  "test/fixtures/posts/no_date.html",
@@ -55,6 +56,18 @@ Gem::Specification.new do |s|
55
56
  "test/fixtures/templates/post.html",
56
57
  "test/fixtures/templates/site.html",
57
58
  "test/howl_test.rb",
59
+ "test/integration_site/config.yml",
60
+ "test/integration_site/generated/images/logo.png",
61
+ "test/integration_site/generated/index.html",
62
+ "test/integration_site/generated/posts/2010/10/17/post.html",
63
+ "test/integration_site/generated/stylesheets/screen.css",
64
+ "test/integration_site/posts/post.md",
65
+ "test/integration_site/site/images/logo.png",
66
+ "test/integration_site/site/index.html",
67
+ "test/integration_site/site/stylesheets/screen.css",
68
+ "test/integration_site/templates/post.html",
69
+ "test/integration_site/templates/site.html",
70
+ "test/integration_test.rb",
58
71
  "test/teststrap.rb"
59
72
  ]
60
73
  s.homepage = %q{http://github.com/crnixon/howl}
@@ -64,6 +77,7 @@ Gem::Specification.new do |s|
64
77
  s.summary = %q{A tiny static website/blog generator.}
65
78
  s.test_files = [
66
79
  "test/howl_test.rb",
80
+ "test/integration_test.rb",
67
81
  "test/teststrap.rb"
68
82
  ]
69
83
 
data/lib/howl/core_ext.rb CHANGED
@@ -11,3 +11,17 @@ class String
11
11
  end
12
12
  end
13
13
 
14
+ def File.binary? name
15
+ open name do |f|
16
+ while (b=f.read(256)) do
17
+ return true if b[ "\0"]
18
+ end
19
+ end
20
+ false
21
+ end
22
+
23
+ class Pathname
24
+ def binary?
25
+ File.binary?(@path)
26
+ end
27
+ end
data/lib/howl/post.rb CHANGED
@@ -3,7 +3,7 @@ module Howl
3
3
  include Comparable
4
4
 
5
5
  def date
6
- view.date? ? Time.parse(view.date) : File.mtime(path)
6
+ view.date? ? Time.parse(view.date.to_s) : File.mtime(path)
7
7
  end
8
8
 
9
9
  def <=>(other)
@@ -31,5 +31,11 @@ module Howl
31
31
  render_view.delete('template')
32
32
  converter.convert(Mustache.render(@content, render_view))
33
33
  end
34
+
35
+ def view_data
36
+ { :site => site,
37
+ :date => date,
38
+ :link => link }
39
+ end
34
40
  end
35
41
  end
data/lib/howl/site.rb CHANGED
@@ -1,9 +1,10 @@
1
1
  module Howl
2
2
  class Site
3
- attr_accessor :root
3
+ attr_accessor :root, :view
4
4
 
5
5
  def initialize(root)
6
6
  @root = Pathname.new(root)
7
+ load_config
7
8
  end
8
9
 
9
10
  def path(path)
@@ -45,10 +46,23 @@ module Howl
45
46
  FileUtils.rm_r(output_path) if File.exist?(output_path)
46
47
  (pages + posts).each do |page|
47
48
  FileUtils.makedirs(page.output_path.dirname)
48
- page.output_path.open("w") do |fh|
49
- fh.write page.render
49
+
50
+ if page.path.binary?
51
+ FileUtils.copy(page.path, page.output_path)
52
+ else
53
+ page.output_path.open("w") do |fh|
54
+ fh.write page.render
55
+ end
50
56
  end
51
57
  end
52
58
  end
59
+
60
+ private
61
+
62
+ def load_config
63
+ view = YAML.load(File.read(path "config.yml")) if path("config.yml").exist?
64
+ view = {} unless view.is_a?(Hash)
65
+ @view = View.new(view)
66
+ end
53
67
  end
54
68
  end
data/lib/howl/template.rb CHANGED
@@ -1,12 +1,20 @@
1
1
  module Howl
2
2
  class Template
3
+ def self.viewables
4
+ @viewables ||= []
5
+ end
6
+
7
+ def self.can_view(*viewables)
8
+ viewables.push(*viewables)
9
+ end
10
+
3
11
  attr_accessor :view, :content, :site, :path, :extension
4
12
 
5
13
  def initialize(path, site)
6
14
  @site = site
7
15
  @path = Pathname.new(path)
8
16
  @extension = @path.extname
9
- load_file
17
+ load_file unless @path.binary?
10
18
  end
11
19
 
12
20
  def ==(other)
@@ -30,14 +38,16 @@ module Howl
30
38
  @converter
31
39
  end
32
40
 
33
- def render(render_view = View.new)
41
+ def render(render_view = nil)
42
+ render_view ||= site.view
43
+ render_view = render_view.dup
34
44
  render_view.merge!(@view)
35
45
  rendered = converter.convert(Mustache.render(@content, render_view))
36
46
  template_name = render_view.delete("template")
37
47
 
38
48
  if template_name
39
49
  template = find_template(template_name)
40
- if template
50
+ if template && template != self
41
51
  rendered = template.render(
42
52
  render_view.merge("content" => rendered))
43
53
  else
@@ -57,6 +67,10 @@ module Howl
57
67
  @site.templates[template_name + converter.extension]
58
68
  end
59
69
 
70
+ def view_data
71
+ { :site => site }
72
+ end
73
+
60
74
  def load_file
61
75
  content = @path.read
62
76
  view, content = content.split("\n\n", 2)
@@ -69,7 +83,8 @@ module Howl
69
83
  view = {}
70
84
  end
71
85
 
72
- @view = View.new(view.merge(:site => site))
86
+ @view = View.new(view)
87
+ @view.merge!(view_data)
73
88
  end
74
89
 
75
90
  def test_for_yaml(view)
data/lib/howl/view.rb CHANGED
@@ -15,5 +15,15 @@ module Howl
15
15
  site.posts
16
16
  end
17
17
  end
18
+
19
+ # filters
20
+
21
+ def format_date
22
+ lambda do |text|
23
+ time = Time.parse(text.to_s)
24
+ time_format = self.date_format || "%b %-d, %Y at %-I:%M %P"
25
+ time.strftime(time_format)
26
+ end
27
+ end
18
28
  end
19
29
  end
@@ -0,0 +1,2 @@
1
+ title: Test Site
2
+ site_key: true
data/test/howl_test.rb CHANGED
@@ -8,6 +8,10 @@ context "Site" do
8
8
  topic.pages == Dir[fixture_path("site/**/*.*")].map { |path| Page.new(path, topic) }
9
9
  }
10
10
 
11
+ should("read its config") {
12
+ topic.view.has_key?(:title)
13
+ }
14
+
11
15
  should("write out all pages") {
12
16
  topic.write_to_disk
13
17
  topic.pages.map { |page|
@@ -0,0 +1,2 @@
1
+ site_name: dce.gitwrite.com
2
+ site_url: "http://dce.gitwrite.com"
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>dce.gitwrite.com</title>
6
+ <link rel="stylesheet" href="/stylesheets/screen.css" type="text/css" />
7
+ <!--[if IE]>
8
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
9
+ <![endif]-->
10
+ </head>
11
+
12
+ <body>
13
+ <div id="container">
14
+ <div id="header">
15
+ <h1><a href="http://dce.gitwrite.com">dce.gitwrite.com</a></h1>
16
+ </div>
17
+
18
+ <div id="content">
19
+ <div class="post">
20
+ <h2>
21
+ <a href="/posts/2010/10/17/post.html">Welcome to GitWrite</a>
22
+ </h2>
23
+ <span class="meta sidebar">
24
+ Oct 17, 2010 at 1:24 pm<br />
25
+ </span>
26
+ <p>Thank you for trying out GitWrite. Your blog lives in a repository at</p>
27
+
28
+ <blockquote><p><code>git://gitwrite.com/blogs/dce.git</code></p></blockquote>
29
+
30
+ <p>Pull it down (with <code>git checkout</code>), make some updates, and push it back.
31
+ In a few moments, your blog will be regenerated to include your new content. Of
32
+ course, you can always make edits through our <a href="http://gitwrite.com/site">web interface</a>, as well.</p>
33
+
34
+ <p class="meta"><a href="/posts/2010/10/17/post.html">Permalink</a></p>
35
+ </div>
36
+
37
+ </div>
38
+
39
+ <div id="footer" class="meta">
40
+ Powered by <a href="http://gitwrite.com" class="image-link"><img src="/images/logo.png" width="100"/></a> &#182; Theme inspired by <a href="http://www.tumblr.com/theme/325">langer</a>
41
+ </div>
42
+ </div>
43
+ </body>
44
+ </html>
@@ -0,0 +1,44 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>dce.gitwrite.com</title>
6
+ <link rel="stylesheet" href="/stylesheets/screen.css" type="text/css" />
7
+ <!--[if IE]>
8
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
9
+ <![endif]-->
10
+ </head>
11
+
12
+ <body>
13
+ <div id="container">
14
+ <div id="header">
15
+ <h1><a href="http://dce.gitwrite.com">dce.gitwrite.com</a></h1>
16
+ </div>
17
+
18
+ <div id="content">
19
+ <div class="post">
20
+ <h2>Welcome to GitWrite</h2>
21
+ <span class="meta sidebar">
22
+ Oct 17, 2010 at 1:24 pm<br />
23
+ </span>
24
+
25
+ <p>Thank you for trying out GitWrite. Your blog lives in a repository at</p>
26
+
27
+ <blockquote><p><code>git://gitwrite.com/blogs/dce.git</code></p></blockquote>
28
+
29
+ <p>Pull it down (with <code>git checkout</code>), make some updates, and push it back.
30
+ In a few moments, your blog will be regenerated to include your new content. Of
31
+ course, you can always make edits through our <a href="http://gitwrite.com/site">web interface</a>, as well.</p>
32
+
33
+
34
+ <p class="meta"><a href="/posts/2010/10/17/post.html">Permalink</a></p>
35
+ </div>
36
+
37
+ </div>
38
+
39
+ <div id="footer" class="meta">
40
+ Powered by <a href="http://gitwrite.com" class="image-link"><img src="/images/logo.png" width="100"/></a> &#182; Theme inspired by <a href="http://www.tumblr.com/theme/325">langer</a>
41
+ </div>
42
+ </div>
43
+ </body>
44
+ </html>
@@ -0,0 +1,60 @@
1
+ h1, h2, h3 {
2
+ font-weight: normal;
3
+ }
4
+
5
+ a {
6
+ text-decoration: none;
7
+ background-color: #FF9;
8
+ color: black;
9
+ padding: 3px;
10
+ }
11
+
12
+ a:hover {
13
+ border-bottom: 1px solid black;
14
+ }
15
+
16
+ #container {
17
+ width: 500px;
18
+ margin: 0 auto;
19
+ font: 14px/1.5 Georgia, sans-serif;
20
+ }
21
+
22
+ #footer {
23
+ margin-top: 60px;
24
+ padding-top: 30px;
25
+ border-top: 1px dotted #999;
26
+ text-align: center;
27
+ }
28
+
29
+ div.post {
30
+ position: relative;
31
+ margin-top: 60px;
32
+ }
33
+
34
+ .meta {
35
+ font-size: .8em;
36
+ color: #999;
37
+ font-style: italic;
38
+ }
39
+
40
+ div.post span.sidebar {
41
+ position: absolute;
42
+ top: 5px;
43
+ left: -225px;
44
+ width: 200px;
45
+ text-align: right;
46
+ border-right: 1px dotted #999;
47
+ padding-right: 10px;
48
+ display: block;
49
+ }
50
+
51
+ a.image-link {
52
+ background: none;
53
+ padding: none;
54
+ border: none;
55
+ }
56
+
57
+ a.image-link img {
58
+ border: 1px solid #999;
59
+ vertical-align: middle;
60
+ }
@@ -0,0 +1,12 @@
1
+ title: Welcome to GitWrite
2
+ template: post
3
+
4
+ Thank you for trying out GitWrite. Your blog lives in a repository at
5
+
6
+ > `git://gitwrite.com/blogs/dce.git`
7
+
8
+ Pull it down (with `git checkout`), make some updates, and push it back.
9
+ In a few moments, your blog will be regenerated to include your new content. Of
10
+ course, you can always make edits through our [web interface][dash], as well.
11
+
12
+ [dash]: http://gitwrite.com/site
@@ -0,0 +1,14 @@
1
+ template: site
2
+
3
+ {{#posts}}
4
+ <div class="post">
5
+ <h2>
6
+ <a href="{{link}}">{{title}}</a>
7
+ </h2>
8
+ <span class="meta sidebar">
9
+ {{#format_date}}{{date}}{{/format_date}}<br />
10
+ </span>
11
+ {{&rendered_content}}
12
+ <p class="meta"><a href="{{link}}">Permalink</a></p>
13
+ </div>
14
+ {{/posts}}
@@ -0,0 +1,60 @@
1
+ h1, h2, h3 {
2
+ font-weight: normal;
3
+ }
4
+
5
+ a {
6
+ text-decoration: none;
7
+ background-color: #FF9;
8
+ color: black;
9
+ padding: 3px;
10
+ }
11
+
12
+ a:hover {
13
+ border-bottom: 1px solid black;
14
+ }
15
+
16
+ #container {
17
+ width: 500px;
18
+ margin: 0 auto;
19
+ font: 14px/1.5 Georgia, sans-serif;
20
+ }
21
+
22
+ #footer {
23
+ margin-top: 60px;
24
+ padding-top: 30px;
25
+ border-top: 1px dotted #999;
26
+ text-align: center;
27
+ }
28
+
29
+ div.post {
30
+ position: relative;
31
+ margin-top: 60px;
32
+ }
33
+
34
+ .meta {
35
+ font-size: .8em;
36
+ color: #999;
37
+ font-style: italic;
38
+ }
39
+
40
+ div.post span.sidebar {
41
+ position: absolute;
42
+ top: 5px;
43
+ left: -225px;
44
+ width: 200px;
45
+ text-align: right;
46
+ border-right: 1px dotted #999;
47
+ padding-right: 10px;
48
+ display: block;
49
+ }
50
+
51
+ a.image-link {
52
+ background: none;
53
+ padding: none;
54
+ border: none;
55
+ }
56
+
57
+ a.image-link img {
58
+ border: 1px solid #999;
59
+ vertical-align: middle;
60
+ }
@@ -0,0 +1,12 @@
1
+ template: site
2
+
3
+ <div class="post">
4
+ <h2>{{title}}</h2>
5
+ <span class="meta sidebar">
6
+ {{#format_date}}{{date}}{{/format_date}}<br />
7
+ </span>
8
+
9
+ {{& content}}
10
+
11
+ <p class="meta"><a href="{{link}}">Permalink</a></p>
12
+ </div>
@@ -0,0 +1,27 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <meta charset="utf-8" />
5
+ <title>{{site_name}}</title>
6
+ <link rel="stylesheet" href="/stylesheets/screen.css" type="text/css" />
7
+ <!--[if IE]>
8
+ <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
9
+ <![endif]-->
10
+ </head>
11
+
12
+ <body>
13
+ <div id="container">
14
+ <div id="header">
15
+ <h1><a href="{{site_url}}">{{site_name}}</a></h1>
16
+ </div>
17
+
18
+ <div id="content">
19
+ {{& content}}
20
+ </div>
21
+
22
+ <div id="footer" class="meta">
23
+ Powered by <a href="http://gitwrite.com" class="image-link"><img src="/images/logo.png" width="100"/></a> &#182; Theme inspired by <a href="http://www.tumblr.com/theme/325">langer</a>
24
+ </div>
25
+ </div>
26
+ </body>
27
+ </html>
@@ -0,0 +1,10 @@
1
+ require 'teststrap'
2
+ include Howl
3
+
4
+ context "Integration Site" do
5
+ setup { Site.new(File.join(File.dirname(__FILE__), "integration_site")) }
6
+
7
+ should "generate successfully" do
8
+ topic.write_to_disk
9
+ end
10
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 4
8
- - 1
9
- version: 0.4.1
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Clinton R. Nixon
@@ -130,6 +130,7 @@ files:
130
130
  - sample_site/site/index.html
131
131
  - sample_site/templates/default.html
132
132
  - sample_site/templates/site.html
133
+ - test/fixtures/config.yml
133
134
  - test/fixtures/posts/first_post.html
134
135
  - test/fixtures/posts/markdown_post.md
135
136
  - test/fixtures/posts/no_date.html
@@ -144,6 +145,18 @@ files:
144
145
  - test/fixtures/templates/post.html
145
146
  - test/fixtures/templates/site.html
146
147
  - test/howl_test.rb
148
+ - test/integration_site/config.yml
149
+ - test/integration_site/generated/images/logo.png
150
+ - test/integration_site/generated/index.html
151
+ - test/integration_site/generated/posts/2010/10/17/post.html
152
+ - test/integration_site/generated/stylesheets/screen.css
153
+ - test/integration_site/posts/post.md
154
+ - test/integration_site/site/images/logo.png
155
+ - test/integration_site/site/index.html
156
+ - test/integration_site/site/stylesheets/screen.css
157
+ - test/integration_site/templates/post.html
158
+ - test/integration_site/templates/site.html
159
+ - test/integration_test.rb
147
160
  - test/teststrap.rb
148
161
  has_rdoc: true
149
162
  homepage: http://github.com/crnixon/howl
@@ -179,4 +192,5 @@ specification_version: 3
179
192
  summary: A tiny static website/blog generator.
180
193
  test_files:
181
194
  - test/howl_test.rb
195
+ - test/integration_test.rb
182
196
  - test/teststrap.rb