middleman-blog 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ .DS_Store
data/.rvmrc ADDED
@@ -0,0 +1 @@
1
+ rvm ruby-1.9.2-p180@middleman-blog
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in middleman-blog.gemspec
4
+ gemspec
@@ -0,0 +1,123 @@
1
+ = middleman-blog
2
+
3
+ Create a blog with Middleman
4
+
5
+ == Features
6
+
7
+ - metadata (yaml) for your post templates (similar to https://github.com/mojombo/jekyll/wiki/YAML-Front-Matter)
8
+ - helper methods to access the metadata from every template/layout file
9
+ - template languages: markdown, textile, rdoc
10
+
11
+ == TODO
12
+
13
+ - test suite
14
+ - better documentation
15
+ - installer/generator
16
+ - more helpers
17
+ - more build-in features (releated posts, tags etc.)
18
+
19
+ == Usage
20
+
21
+ Example: https://github.com/matt-hh/middleman-blog-example
22
+
23
+ 1. Install
24
+
25
+ gem install middleman-blog
26
+
27
+ Additionally you need one of the following gems for your post templates: Kramdown, Maruku, RedCloth, BlueCloth, RDiscount ...
28
+
29
+ 2. Create your project
30
+
31
+ mm-init your-middleman-project
32
+
33
+ 3. Create config/blogs.yml with default values
34
+
35
+ blog:
36
+ title: My Blog
37
+ author: your name
38
+ mail: your mail
39
+ whatever: a value
40
+ another-blog:
41
+ title: My second Blog
42
+
43
+ Yes, you can define default values for more than one blog...
44
+
45
+ 4. Create layout files:
46
+
47
+ blog_index.haml:
48
+
49
+ %h1= current_blog_value('title')
50
+ = yield
51
+
52
+ blog_post.haml:
53
+
54
+ %h1= current_post_value('title')
55
+ = yield
56
+
57
+ 5. Activate feature in config.rb
58
+
59
+ require "middleman-blog"
60
+ activate :blog_engine
61
+
62
+ page "/blog/index.html", :layout => :blog_index, :layout_engine => 'haml'
63
+ page "/blog/*", :layout => :blog_post, :layout_engine => 'haml'
64
+
65
+ page "/another-blog/index.html", :blog_post => :blog_index, :layout_engine => 'haml'
66
+ page "/another-blog/*", :blog_post => :blog_post, :layout_engine => 'haml'
67
+
68
+ 6. Create directories in your source folder
69
+
70
+ mkdir blog
71
+ mkdir my-second-blog
72
+
73
+ In these folders you can create your posts.
74
+
75
+ blog/my-first-post.html.md
76
+
77
+ title: Title of my first post
78
+ date: 2011-06-05
79
+ ----
80
+
81
+
82
+ My first blog post...
83
+
84
+ Important: 2 newlines between "----" and "My first..."
85
+
86
+ == Metadata
87
+
88
+ - "----\n\n\n" separates the metadata from your post data.
89
+ - metadata supports ERB
90
+ - you can define whatever you want
91
+ - special keys for blogs.yml:
92
+ sort_by: name of another key (default is date)
93
+ sort_direction: normal | reverse (default is reverse)
94
+ - special keys for yaml header:
95
+ date: default is mtime for template file
96
+
97
+ == Helper methods
98
+
99
+ - current_blog
100
+ - current_blog_meta(key) or current_blog[key]
101
+ - current_post
102
+ - current_post_meta(key) or current_post[key]
103
+ - next_post
104
+ - prev_post
105
+ - current_blog_ident
106
+ - current_post_ident
107
+ - current_post_index
108
+
109
+ === Examples
110
+
111
+ - Link to the next post
112
+
113
+ link_to next_post['title'], next_post['link']
114
+
115
+ - List of 10 last posts
116
+
117
+ %ul
118
+ - current_blog["posts"][0,10].each do |post|
119
+ %li= link_to post['title'], post['link']
120
+
121
+ == Links
122
+
123
+ * https://github.com/tdreyno/middleman
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,3 @@
1
+ require "middleman-blog/separator"
2
+ require "middleman-blog/tilt"
3
+ require "middleman-blog/blog_engine"
@@ -0,0 +1,108 @@
1
+ module Middleman
2
+ module Features
3
+ module BlogEngine
4
+
5
+ class << self
6
+ def registered(app)
7
+ app.helpers BlogEngine::Helpers
8
+ end
9
+ alias :included :registered
10
+ end
11
+
12
+ module Helpers
13
+ def blog(blog_ident)
14
+ blogs[blog_ident] || {"posts" => []}
15
+ end
16
+ def current_blog
17
+ blog(current_blog_ident)
18
+ end
19
+ def blog_meta(blog_ident, key)
20
+ blog(blog_ident)[key] || no_value
21
+ end
22
+ def current_blog_meta(key)
23
+ blog_meta(current_blog_ident,key)
24
+ end
25
+ def blog_post(blog_ident, post_ident)
26
+ blog(blog_ident)["posts"].find {|post| post["ident"] == post_ident } || {}
27
+ end
28
+ def current_post
29
+ blog_post(current_blog_ident, current_post_ident)
30
+ end
31
+ def blog_post_meta(blog_ident, post_ident, key)
32
+ blog_post(blog_ident, post_ident)[key] || blog_meta(blog_ident, key) || no_value
33
+ end
34
+ def current_post_meta(key)
35
+ blog_post_meta(current_blog_ident, current_post_ident, key)
36
+ end
37
+ def next_post
38
+ current_blog["posts"][current_post_index + 1]
39
+ end
40
+ def prev_post
41
+ current_blog["posts"][current_post_index - 1]
42
+ end
43
+ def current_blog_ident
44
+ (File.dirname request_path).gsub(%r{^/}, '') || "blog"
45
+ end
46
+ def current_post_ident
47
+ File.basename(request_path).split(".", 2)[0]
48
+ end
49
+ def current_post_index
50
+ current_blog["posts"].index current_post
51
+ end
52
+
53
+ def blogs
54
+ Middleman::Features::BlogEngine::Meta.new(self).data
55
+ end
56
+
57
+ private
58
+ def request_path
59
+ self.env['REQUEST_PATH'] || ""
60
+ end
61
+ def no_value
62
+ "-- no value --"
63
+ end
64
+
65
+ end
66
+
67
+ class Meta
68
+ attr_reader :data
69
+
70
+ def initialize(app)
71
+ @app = app
72
+
73
+ config_file = File.join(@app.class.root, "config", "blogs.yml")
74
+ raise "could not find \"#{config_file}\" " unless File.exists?(config_file)
75
+ blog_config = YAML.load_file(config_file)
76
+ @data = blog_config
77
+
78
+ blog_config.each do |blog_ident,blog_values|
79
+ blog_source_dir = File.join(@app.class.views, blog_ident)
80
+ @data[blog_ident]["posts"] = []
81
+ Dir["#{blog_source_dir}/*.html.*"].each do |file|
82
+ if file =~ /.*\.html\.(markdown|mkd|md|textile|rdoc)$/
83
+ post_ident = File.basename(file).split(".", 2)[0]
84
+
85
+ post_meta_yml = ERB.new( (File.read(file).split(/#{Middleman::Blog::SEPARATOR}/, 2))[0] || "" ).result
86
+ post_meta = YAML.load(post_meta_yml) || {}
87
+ post_meta["ident"] = post_ident
88
+ post_meta["link"] = "/%s" % File.join( blog_ident, File.basename(file, '.*') )
89
+ post_meta["date"] = File.mtime(file).to_s unless post_meta["date"]
90
+ @data[blog_ident]["posts"] << post_meta
91
+ end
92
+ end
93
+
94
+ sort_key = @data[blog_ident]["sort_key"] || "date"
95
+ @data[blog_ident]["posts"].sort_by! { |post| post[sort_key] }
96
+ sort_direction = @data[blog_ident]["sort_direction"] || "reverse"
97
+ @data[blog_ident]["posts"].reverse! if sort_direction == "reverse"
98
+ end
99
+
100
+ end
101
+
102
+ end
103
+
104
+
105
+
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Blog
3
+ SEPARATOR = '----\n\n\n'
4
+ end
5
+ end
@@ -0,0 +1,54 @@
1
+ module Tilt
2
+
3
+ module MiddlemanBlogTemplate
4
+ def prepare
5
+ @data = data.gsub(/^.*?#{Middleman::Blog::SEPARATOR}/m, '')
6
+ super
7
+ end
8
+ end
9
+
10
+
11
+ # MARKDOWN
12
+
13
+ class MarukuMiddlemanBlogTemplate < MarukuTemplate
14
+ include Tilt::MiddlemanBlogTemplate
15
+ end
16
+ register MarukuMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
17
+
18
+ class KramdownMiddlemanBlogTemplate < KramdownTemplate
19
+ include Tilt::MiddlemanBlogTemplate
20
+ end
21
+ register KramdownMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
22
+
23
+ class BlueClothMiddlemanBlogTemplate < BlueClothTemplate
24
+ include Tilt::MiddlemanBlogTemplate
25
+ end
26
+ register BlueClothMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
27
+
28
+ class RedcarpetMiddlemanBlogTemplate < RedcarpetTemplate
29
+ include Tilt::MiddlemanBlogTemplate
30
+ end
31
+ register RedcarpetMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
32
+
33
+ class RDiscountMiddlemanBlogTemplate < RDiscountTemplate
34
+ include Tilt::MiddlemanBlogTemplate
35
+ end
36
+ register RDiscountMiddlemanBlogTemplate, 'markdown', 'mkd', 'md'
37
+
38
+ # TEXTILE
39
+
40
+ class RedClothMiddlemanBlogTemplate < RedClothTemplate
41
+ include Tilt::MiddlemanBlogTemplate
42
+ end
43
+ register RedClothMiddlemanBlogTemplate, 'textile'
44
+
45
+ # RDOC
46
+
47
+ class RDocMiddlemanBlogTemplate < RDocTemplate
48
+ include Tilt::MiddlemanBlogTemplate
49
+ end
50
+ register RDocMiddlemanBlogTemplate, 'rdoc'
51
+
52
+
53
+
54
+ end
@@ -0,0 +1,5 @@
1
+ module Middleman
2
+ module Blog
3
+ VERSION = "0.0.1"
4
+ end
5
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "middleman-blog/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "middleman-blog"
7
+ s.version = Middleman::Blog::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Matthias Döring"]
10
+ s.email = ["matt@foryourcontent.de"]
11
+ s.homepage = "http://rubygems.org/gems/middleman-blog"
12
+ s.summary = %q{Create a blog with Middleman}
13
+ s.description = %q{Create a blog with Middleman}
14
+
15
+ s.rubyforge_project = "middleman-blog"
16
+
17
+ s.add_dependency "middleman", "~> 1.2.0"
18
+
19
+ s.files = `git ls-files`.split("\n")
20
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
21
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
+ s.require_paths = ["lib"]
23
+ end
metadata ADDED
@@ -0,0 +1,77 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: middleman-blog
3
+ version: !ruby/object:Gem::Version
4
+ prerelease:
5
+ version: 0.0.1
6
+ platform: ruby
7
+ authors:
8
+ - "Matthias D\xC3\xB6ring"
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+
13
+ date: 2011-06-06 00:00:00 +02:00
14
+ default_executable:
15
+ dependencies:
16
+ - !ruby/object:Gem::Dependency
17
+ name: middleman
18
+ prerelease: false
19
+ requirement: &id001 !ruby/object:Gem::Requirement
20
+ none: false
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 1.2.0
25
+ type: :runtime
26
+ version_requirements: *id001
27
+ description: Create a blog with Middleman
28
+ email:
29
+ - matt@foryourcontent.de
30
+ executables: []
31
+
32
+ extensions: []
33
+
34
+ extra_rdoc_files: []
35
+
36
+ files:
37
+ - .gitignore
38
+ - .rvmrc
39
+ - Gemfile
40
+ - README.rdoc
41
+ - Rakefile
42
+ - lib/middleman-blog.rb
43
+ - lib/middleman-blog/blog_engine.rb
44
+ - lib/middleman-blog/separator.rb
45
+ - lib/middleman-blog/tilt.rb
46
+ - lib/middleman-blog/version.rb
47
+ - middleman-blog.gemspec
48
+ has_rdoc: true
49
+ homepage: http://rubygems.org/gems/middleman-blog
50
+ licenses: []
51
+
52
+ post_install_message:
53
+ rdoc_options: []
54
+
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
+
71
+ rubyforge_project: middleman-blog
72
+ rubygems_version: 1.6.2
73
+ signing_key:
74
+ specification_version: 3
75
+ summary: Create a blog with Middleman
76
+ test_files: []
77
+