middleman-org 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +5 -0
- data/Gemfile +20 -0
- data/README.md +58 -0
- data/Rakefile +14 -0
- data/features/support/env.rb +4 -0
- data/lib/middleman-org/extension.rb +52 -0
- data/lib/middleman-org/helpers.rb +38 -0
- data/lib/middleman-org/org_article.rb +102 -0
- data/lib/middleman-org/org_data.rb +56 -0
- data/lib/middleman-org/version.rb +5 -0
- data/lib/middleman-org.rb +7 -0
- data/lib/middleman_extension.rb +1 -0
- data/middleman-org.gemspec +26 -0
- metadata +115 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f2cda372c2e2651915077bfb548761d0ec832213
|
4
|
+
data.tar.gz: b25e56515d08b6a858414f159225c9c066601182
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: cb94d0dc36a263675e6f65a718523fed6ff48e5db5fbb2473ad295393d164671993fb8eb13d7855bb57bac78a441087d05eb16b60d7e30850bd17ea216d3edc8
|
7
|
+
data.tar.gz: e8cbe2ddae85763996df5eca673dafc8bf8cbb29acb110c0d1a58613ef2c51f298d9cc2eff9c058c34331149b086045639b706f79ea94e968f521515e50c809b
|
data/.gitignore
ADDED
data/Gemfile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# If you do not have OpenSSL installed, update
|
2
|
+
# the following line to use "http://" instead
|
3
|
+
source 'https://rubygems.org'
|
4
|
+
|
5
|
+
# Specify your gem's dependencies in middleman-org.gemspec
|
6
|
+
gemspec
|
7
|
+
|
8
|
+
group :development do
|
9
|
+
gem 'rake'
|
10
|
+
gem 'rdoc'
|
11
|
+
gem 'yard'
|
12
|
+
gem 'pry'
|
13
|
+
end
|
14
|
+
|
15
|
+
group :test do
|
16
|
+
gem 'cucumber'
|
17
|
+
gem 'fivemat'
|
18
|
+
gem 'aruba'
|
19
|
+
gem 'rspec'
|
20
|
+
end
|
data/README.md
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
# middleman-org
|
2
|
+
|
3
|
+
|
4
|
+
## What and Why
|
5
|
+
|
6
|
+
`middleman-org` is an extention for [middleman](https://middlemanapp.com) to generate static pages from [org file](http://orgmode.org).
|
7
|
+
It is highly inspired by the offical blog extention [middleman-blog](https://github.com/middleman/middleman-blog), but it is not another blogging extention.
|
8
|
+
|
9
|
+
## Advantages of using `middleman-org`
|
10
|
+
|
11
|
+
### Linking
|
12
|
+
|
13
|
+
Org mode is powerful as a whole system. You expect connections between files. Or being able to reference some kind of resource files (e.g. input data, image etc.) within org. `middleman-org` preserve the complete structure of your system, so that you will have the whole set exported with no breaking links.
|
14
|
+
|
15
|
+
### No more `front mater`
|
16
|
+
|
17
|
+
Is it just me or... I found the `yaml front mater` is just annoying in such scenario. You don't want to pollute your org files with it, do you? `middleman-org` uses native org-mode in buffer settings as metadata of your article.
|
18
|
+
So instead of
|
19
|
+
|
20
|
+
```yaml
|
21
|
+
---
|
22
|
+
title: my polluted article
|
23
|
+
date: 2015-04-09
|
24
|
+
tags: polluted, lame
|
25
|
+
---
|
26
|
+
```
|
27
|
+
|
28
|
+
You can use
|
29
|
+
|
30
|
+
```org
|
31
|
+
#+TITLE: my awesome article
|
32
|
+
#+DATE: <2015-04-09 Thu>
|
33
|
+
#+KEYWORDS: awesome nice
|
34
|
+
```
|
35
|
+
|
36
|
+
### Selective Publish
|
37
|
+
|
38
|
+
This is implemented by [org-ruby](https://github.com/bdewey/org-ruby), the rendering engine we use in `middleman-org`. Just simply apply [export settings](http://orgmode.org/manual/Export-settings.html) natively in your org file, sections with exclusion tags will not be published.
|
39
|
+
|
40
|
+
## Installation
|
41
|
+
|
42
|
+
Add `middleman-org` to your `Gemfile` and run `bundle install`.
|
43
|
+
## Configuration
|
44
|
+
|
45
|
+
And activate it in `config.rb`.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
activate :org
|
49
|
+
```
|
50
|
+
|
51
|
+
With default settings, create a folder `org` inside your `source` folder and dump all your org files into it.
|
52
|
+
If you use git to manage your org files, it is highly recommaned to add your org repository as a submodule.
|
53
|
+
|
54
|
+
option | default | meaning
|
55
|
+
---|---|---
|
56
|
+
`layout` | 'layout' | article specific layout
|
57
|
+
`root` | 'org' | root folder for org files (relative to `source` folder)
|
58
|
+
`prefix` | nil | prefix on root and destination path
|
data/Rakefile
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'bundler'
|
2
|
+
Bundler::GemHelper.install_tasks
|
3
|
+
|
4
|
+
require 'cucumber/rake/task'
|
5
|
+
|
6
|
+
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
|
7
|
+
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
|
8
|
+
end
|
9
|
+
|
10
|
+
require 'rake/clean'
|
11
|
+
|
12
|
+
task test: ['cucumber']
|
13
|
+
|
14
|
+
task default: :test
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'middleman-org/org_data'
|
2
|
+
require 'middleman-org/org_article'
|
3
|
+
require 'middleman-org/helpers'
|
4
|
+
|
5
|
+
module Middleman
|
6
|
+
class OrgExtension < ::Middleman::Extension
|
7
|
+
option :layout, 'layout', 'article specific layout'
|
8
|
+
option :root, 'org', 'source folder for org files'
|
9
|
+
option :prefix, nil, 'prefix on destination and root path'
|
10
|
+
# option :resources, 'resources', 'folder name for resources'
|
11
|
+
|
12
|
+
attr_reader :data
|
13
|
+
|
14
|
+
self.defined_helpers = [Middleman::Org::Helpers]
|
15
|
+
def initialize(app, options_hash = {}, &block)
|
16
|
+
# Call super to build options from the options_hash
|
17
|
+
super
|
18
|
+
|
19
|
+
# Require libraries only when activated
|
20
|
+
require 'org-ruby'
|
21
|
+
require 'middleman-org/org_data'
|
22
|
+
|
23
|
+
options.root = File.join(options.prefix, options.root) if options.prefix
|
24
|
+
|
25
|
+
app.after_configuration do
|
26
|
+
template_extensions org: :html
|
27
|
+
end
|
28
|
+
|
29
|
+
# set up your extension
|
30
|
+
# puts options.my_option
|
31
|
+
end
|
32
|
+
|
33
|
+
def after_configuration
|
34
|
+
::Middleman::Org.controller = self
|
35
|
+
|
36
|
+
# Make sure ActiveSupport's TimeZone stuff has something to work with,
|
37
|
+
# allowing people to set their desired time zone via Time.zone or
|
38
|
+
# set :time_zone
|
39
|
+
Time.zone = app.config[:time_zone] if app.config[:time_zone]
|
40
|
+
time_zone = Time.zone || 'UTC'
|
41
|
+
zone_default = Time.find_zone!(time_zone)
|
42
|
+
unless zone_default
|
43
|
+
raise 'Value assigned to time_zone not recognized.'
|
44
|
+
end
|
45
|
+
Time.zone_default = zone_default
|
46
|
+
|
47
|
+
@data = Org::OrgData.new(@app, self, options)
|
48
|
+
@app.sitemap.register_resource_list_manipulator(:"org_articles", @data, false)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Middleman
|
2
|
+
module Org
|
3
|
+
|
4
|
+
def self.controller
|
5
|
+
@controller ||= nil
|
6
|
+
end
|
7
|
+
|
8
|
+
def self.controller=(v)
|
9
|
+
@controller = v
|
10
|
+
end
|
11
|
+
|
12
|
+
module Helpers
|
13
|
+
def self.included(base)
|
14
|
+
end
|
15
|
+
|
16
|
+
def org_controller
|
17
|
+
::Middleman::Org.controller
|
18
|
+
end
|
19
|
+
|
20
|
+
def org_data
|
21
|
+
org_controller.data
|
22
|
+
end
|
23
|
+
|
24
|
+
def current_article
|
25
|
+
article = current_resource
|
26
|
+
if article && article.is_a?(OrgArticle)
|
27
|
+
article
|
28
|
+
else
|
29
|
+
nil
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def articles
|
34
|
+
org_data.articles
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'active_support/time_with_zone'
|
2
|
+
require 'active_support/core_ext/time/acts_like'
|
3
|
+
require 'active_support/core_ext/time/calculations'
|
4
|
+
require 'nokogiri'
|
5
|
+
|
6
|
+
module Middleman
|
7
|
+
module Org
|
8
|
+
|
9
|
+
module OrgArticle
|
10
|
+
def self.extended(base)
|
11
|
+
base.class.send(:attr_accessor, :org_controller)
|
12
|
+
end
|
13
|
+
|
14
|
+
def org_data
|
15
|
+
org_controller.data
|
16
|
+
end
|
17
|
+
|
18
|
+
def org_options
|
19
|
+
org_controller.options
|
20
|
+
end
|
21
|
+
|
22
|
+
IN_BUFFER_SETTING_REGEXP = /^#\+(\w+):\s*(.*)$/
|
23
|
+
|
24
|
+
def in_buffer_setting
|
25
|
+
return @_in_buffer_setting if @_in_buffer_setting
|
26
|
+
|
27
|
+
@_in_buffer_setting = {}
|
28
|
+
File.open(source_file, 'r') do |f|
|
29
|
+
f.each_line do |line|
|
30
|
+
if line =~ IN_BUFFER_SETTING_REGEXP
|
31
|
+
@_in_buffer_setting[$1] = $2
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
@_in_buffer_setting
|
36
|
+
end
|
37
|
+
|
38
|
+
def render(opts={}, locs={}, &block)
|
39
|
+
unless opts.has_key?(:layout)
|
40
|
+
opts[:layout] = org_options.layout if opts[:layout].nil?
|
41
|
+
# Convert to a string unless it's a boolean
|
42
|
+
opts[:layout] = opts[:layout].to_s if opts[:layout].is_a? Symbol
|
43
|
+
end
|
44
|
+
|
45
|
+
content = super(opts, locs, &block)
|
46
|
+
fix_links(content)
|
47
|
+
end
|
48
|
+
|
49
|
+
def fix_links(content)
|
50
|
+
html = ::Nokogiri::HTML(content)
|
51
|
+
html.xpath("//@src | //@href | //@poster").each do |attribute|
|
52
|
+
attribute.value = attribute.value.gsub(/^(.+)\.org$/, '\1.html')
|
53
|
+
end
|
54
|
+
html.to_s
|
55
|
+
end
|
56
|
+
|
57
|
+
def title
|
58
|
+
in_buffer_setting['TITLE'] || File.basename(source_file, '.*')
|
59
|
+
end
|
60
|
+
|
61
|
+
def tags
|
62
|
+
article_tags = in_buffer_setting['KEYWORDS']
|
63
|
+
return [] unless article_tags
|
64
|
+
|
65
|
+
if article_tags.is_a? String
|
66
|
+
article_tags.split(' ').map(&:strip)
|
67
|
+
else
|
68
|
+
Array(article_tags).map(&:to_s)
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
def published?
|
73
|
+
true
|
74
|
+
end
|
75
|
+
|
76
|
+
def body
|
77
|
+
render layout: false
|
78
|
+
end
|
79
|
+
|
80
|
+
def date
|
81
|
+
return @_date if @_date
|
82
|
+
|
83
|
+
@_date = in_buffer_setting['DATE']
|
84
|
+
|
85
|
+
# frontmatter_date = data['date']
|
86
|
+
|
87
|
+
# # First get the date from frontmatter
|
88
|
+
# if frontmatter_date.is_a? Time
|
89
|
+
# @_date = frontmatter_date.in_time_zone
|
90
|
+
# else
|
91
|
+
# @_date = Time.zone.parse(frontmatter_date.to_s)
|
92
|
+
# end
|
93
|
+
|
94
|
+
@_date
|
95
|
+
end
|
96
|
+
|
97
|
+
def slug
|
98
|
+
end
|
99
|
+
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
@@ -0,0 +1,56 @@
|
|
1
|
+
require 'middleman-core/util'
|
2
|
+
|
3
|
+
module Middleman
|
4
|
+
module Org
|
5
|
+
|
6
|
+
class OrgData
|
7
|
+
attr_reader :options
|
8
|
+
attr_reader :controller
|
9
|
+
|
10
|
+
def initialize(app, controller, options)
|
11
|
+
@app = app
|
12
|
+
@options = options
|
13
|
+
@controller = controller
|
14
|
+
|
15
|
+
@_articles = []
|
16
|
+
end
|
17
|
+
|
18
|
+
def articles
|
19
|
+
@_articles
|
20
|
+
end
|
21
|
+
|
22
|
+
def tags
|
23
|
+
[]
|
24
|
+
end
|
25
|
+
|
26
|
+
def manipulate_resource_list(resources)
|
27
|
+
@_posts = []
|
28
|
+
resources.each do |resource|
|
29
|
+
next unless resource.path =~ /^#{options.root}/
|
30
|
+
|
31
|
+
resource.destination_path = resource.path.gsub(/^#{options.root}/,
|
32
|
+
options.prefix)
|
33
|
+
if File.extname(resource.source_file) == '.org'
|
34
|
+
article = convert_to_article resource
|
35
|
+
puts article.source_file
|
36
|
+
next unless publishable?(article)
|
37
|
+
@_articles << article
|
38
|
+
end
|
39
|
+
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
def publishable?(article)
|
44
|
+
@app.environment == :development || article.published?
|
45
|
+
end
|
46
|
+
|
47
|
+
def convert_to_article(resource)
|
48
|
+
return resource if resource.is_a?(OrgArticle)
|
49
|
+
resource.extend OrgArticle
|
50
|
+
resource.org_controller = controller
|
51
|
+
resource
|
52
|
+
end
|
53
|
+
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'middleman-org'
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$LOAD_PATH.push File.expand_path('../lib', __FILE__)
|
3
|
+
require 'middleman-org/version'
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = 'middleman-org'
|
7
|
+
s.version = Middleman::Org::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ['Xiaoxing Hu']
|
10
|
+
s.email = ['dawnstar.hu@gmail.com']
|
11
|
+
s.homepage = 'http://github.com/xiaoxinghu/middleman-org'
|
12
|
+
s.summary = %q{org-mode extension for middleman}
|
13
|
+
s.description = %q{Middleman extension for publishing org-mode project}
|
14
|
+
s.files = `git ls-files`.split("\n")
|
15
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
17
|
+
s.require_paths = ['lib']
|
18
|
+
s.license = 'MIT'
|
19
|
+
# The version of middleman-core your extension depends on
|
20
|
+
s.add_runtime_dependency('middleman-core', ['~> 3.3'])
|
21
|
+
|
22
|
+
# Additional dependencies
|
23
|
+
s.add_runtime_dependency('org-ruby', '~> 0.9.12')
|
24
|
+
s.add_runtime_dependency('addressable', '~> 2.3')
|
25
|
+
s.add_runtime_dependency('nokogiri', '~> 1.6')
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: middleman-org
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Xiaoxing Hu
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2015-04-09 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: middleman-core
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.3'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.3'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: org-ruby
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 0.9.12
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 0.9.12
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: addressable
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '2.3'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '2.3'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: nokogiri
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.6'
|
62
|
+
type: :runtime
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.6'
|
69
|
+
description: Middleman extension for publishing org-mode project
|
70
|
+
email:
|
71
|
+
- dawnstar.hu@gmail.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- README.md
|
79
|
+
- Rakefile
|
80
|
+
- features/support/env.rb
|
81
|
+
- lib/middleman-org.rb
|
82
|
+
- lib/middleman-org/extension.rb
|
83
|
+
- lib/middleman-org/helpers.rb
|
84
|
+
- lib/middleman-org/org_article.rb
|
85
|
+
- lib/middleman-org/org_data.rb
|
86
|
+
- lib/middleman-org/version.rb
|
87
|
+
- lib/middleman_extension.rb
|
88
|
+
- middleman-org.gemspec
|
89
|
+
homepage: http://github.com/xiaoxinghu/middleman-org
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.4.6
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: org-mode extension for middleman
|
113
|
+
test_files:
|
114
|
+
- features/support/env.rb
|
115
|
+
has_rdoc:
|