blogeen 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/README ADDED
@@ -0,0 +1,12 @@
1
+ Blogín
2
+ ======
3
+
4
+ Blogín (blogeen) is a very simple website generator, which takes plain input,
5
+ pumps it through some formatting, wraps the result in a template, and ends up
6
+ with a complete tree of HTML.
7
+
8
+ Installation
9
+ ------------
10
+
11
+ Just install the gem:
12
+ gem install --remote blogeen
@@ -0,0 +1,39 @@
1
+ require 'rubygems'
2
+ require 'rake/clean'
3
+ require 'rake/testtask'
4
+ require 'rake/gempackagetask'
5
+ require 'rake/rdoctask'
6
+
7
+ spec = Gem::Specification.new do |s|
8
+ s.name = "blogeen"
9
+ s.author = 'JJ Buckley'
10
+ s.email = 'jj@bjjb.org'
11
+ s.rubyforge_project = 'blogeen'
12
+ s.homepage = 'http://blogeen.rubyforge.org'
13
+ s.has_rdoc = true
14
+ s.rdoc_options << '--title' << 'Blogín'
15
+ s.summary = "A simple blog system"
16
+ s.version = '0.0.1'
17
+ s.executables << 'blogeen'
18
+ s.add_dependency 'rdiscount'
19
+ s.files = FileList.new(
20
+ "README*",
21
+ "Rakefile",
22
+ "lib/**/*.rb",
23
+ "test/**/*.rb",
24
+ "bin/*"
25
+ )
26
+ end
27
+
28
+ Rake::GemPackageTask.new(spec).define
29
+
30
+ Rake::TestTask.new do |t|
31
+ t.libs << 'test'
32
+ t.test_files = FileList['test/test*.rb']
33
+ end
34
+
35
+ Rake::RDocTask.new do |t|
36
+ t.main = "README"
37
+ t.rdoc_dir = 'doc'
38
+ t.rdoc_files.include("README", "lib/**/*.rb")
39
+ end
@@ -0,0 +1,4 @@
1
+ #!/usr/bin/env ruby
2
+ require 'rubygems'
3
+ require 'blogeen'
4
+ Blogeen.new.publish
@@ -0,0 +1,25 @@
1
+ require File.join(File.dirname(__FILE__), 'blogeen/page')
2
+
3
+ # A very simple website generator
4
+ class Blogeen
5
+ def initialize(options = {})
6
+ @pages = load_pages
7
+ end
8
+
9
+ def publish
10
+ @pages.select(&:out_of_date?).each(&:publish)
11
+ #update_index
12
+ end
13
+
14
+ private
15
+ def load_pages
16
+ pages = Dir[input_pattern].map do |f|
17
+ Page.new(f)
18
+ end
19
+ end
20
+
21
+ def input_pattern
22
+ "*.txt"
23
+ end
24
+ end
25
+ # vim:tw=79:sw=2:ts=2
@@ -0,0 +1,130 @@
1
+ require 'rubygems'
2
+ require 'rdiscount'
3
+ require 'erb'
4
+ require 'yaml'
5
+
6
+ class Blogeen
7
+ # A single Blogeen page - handles the text, YAML and HTML content
8
+ class Page
9
+ def initialize(textfile, options = {})
10
+ @heading = options[:heading]
11
+ @subheading = options[:subheading]
12
+ @textfile = textfile
13
+ @basename = File.basename(textfile, '.txt')
14
+ @yamlfile = "#{@basename}.yml"
15
+ @htmlfile = File.join(output_directory, "#{@basename}.html")
16
+ end
17
+
18
+ # Determines whether something needs to be done to update any of the Page's
19
+ # files
20
+ def out_of_date?
21
+ return true unless File.exists?(htmlfile)
22
+ return true unless File.mtime(htmlfile) > File.mtime(yamlfile)
23
+ return true unless File.mtime(htmlfile) > File.mtime(template)
24
+ return true unless File.exists?(yamlfile)
25
+ return true unless File.mtime(yamlfile) > File.mtime(textfile)
26
+ end
27
+
28
+ # Writes this Page's HTML to its HTML file
29
+ def publish
30
+ File.open(@htmlfile, 'w') do |f|
31
+ f.print(html)
32
+ end
33
+ rescue
34
+ File.unlink(@htmlfile) if File.exists?(@htmlfile)
35
+ raise $!
36
+ end
37
+
38
+ # The HTML for this Page
39
+ def html
40
+ @html ||= ERB.new(File.read(template)).result(binding)
41
+ end
42
+
43
+ # The ERB template which is used for the Page's layout
44
+ def template
45
+ "page.html.erb"
46
+ end
47
+
48
+ # The intermediate Page's data, from the YAML file
49
+ def data
50
+ @data ||= YAML.load(yaml)
51
+ end
52
+
53
+ # Where the HTML is written
54
+ def htmlfile
55
+ @htmlfile
56
+ end
57
+
58
+ # Where the YAML is written and edited
59
+ def yamlfile
60
+ @yamlfile
61
+ end
62
+
63
+ # Where the text comes from
64
+ def textfile
65
+ @textfile
66
+ end
67
+
68
+ protected
69
+
70
+ def heading
71
+ @heading ||= 'b j j b . o r g'
72
+ end
73
+
74
+ def subheading
75
+ @subheading ||= 'the magpies are struggling'
76
+ end
77
+
78
+ def yaml
79
+ return @yaml unless @yaml.nil?
80
+ @yaml = if File.exists?(yamlfile)
81
+ YAML.load(File.read(yamlfile))
82
+ else
83
+ title = @basename.split('-').map do |word|
84
+ word.sub(/^(\w)/) { |c| c.upcase }
85
+ end.join(' ')
86
+ format = 'markdown'
87
+ summary = ""
88
+ time = File.ctime(textfile)
89
+ author = ENV['USER']
90
+ yaml = {
91
+ "title" => title,
92
+ "format" => format,
93
+ "summary" => summary,
94
+ "time" => time,
95
+ "author" => author,
96
+ "content" => text
97
+ }.to_yaml
98
+ File.open(yamlfile, 'w') { |f| YAML.dump(yaml, f) }
99
+ yaml
100
+ end
101
+ end
102
+
103
+ def text
104
+ @text ||= File.read(textfile)
105
+ end
106
+
107
+ def content
108
+ @content ||= formatter.new(text).to_html
109
+ end
110
+
111
+ def title
112
+ @title ||= data['title']
113
+ end
114
+
115
+ def formatter
116
+ @@formatters[data['format']]
117
+ end
118
+
119
+ def time
120
+ @time ||= data['time'].strftime('%Y-%m-%d %H:%M')
121
+ end
122
+
123
+ def output_directory
124
+ 'public'
125
+ end
126
+
127
+ @@formatters = { 'markdown' => RDiscount }
128
+ end
129
+ end
130
+ # vim:ts=2:sw=2:tw=79
@@ -0,0 +1,9 @@
1
+ require 'test/unit'
2
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'blogeen')
3
+
4
+ class TestBlogeen < Test::Unit::TestCase
5
+ def test_initialize
6
+ end
7
+ end
8
+
9
+ # vim:ts=2:sw=2:tw=79
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: blogeen
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - JJ Buckley
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-06-07 00:00:00 +02:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: rdiscount
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ description:
26
+ email: jj@bjjb.org
27
+ executables:
28
+ - blogeen
29
+ extensions: []
30
+
31
+ extra_rdoc_files: []
32
+
33
+ files:
34
+ - README
35
+ - Rakefile
36
+ - lib/blogeen.rb
37
+ - lib/blogeen/page.rb
38
+ - test/test_blogeen.rb
39
+ - bin/blogeen
40
+ has_rdoc: true
41
+ homepage: http://blogeen.rubyforge.org
42
+ post_install_message:
43
+ rdoc_options:
44
+ - --title
45
+ - "Blog\xC3\xADn"
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ requirements:
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: "0"
53
+ version:
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ requirements:
56
+ - - ">="
57
+ - !ruby/object:Gem::Version
58
+ version: "0"
59
+ version:
60
+ requirements: []
61
+
62
+ rubyforge_project: blogeen
63
+ rubygems_version: 1.3.1
64
+ signing_key:
65
+ specification_version: 2
66
+ summary: A simple blog system
67
+ test_files: []
68
+