middleman-org 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/middleman-org/extension.rb +38 -36
- data/lib/middleman-org/version.rb +1 -1
- data/middleman-org.gemspec +1 -1
- metadata +4 -7
- data/lib/middleman-org/helpers.rb +0 -52
- data/lib/middleman-org/org_article.rb +0 -116
- data/lib/middleman-org/org_data.rb +0 -58
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf5aaf69f1bc7cba22e779756677d0908873b125
|
4
|
+
data.tar.gz: 4b6cb340f6ddf4dc8b8454d8baf4e8e234d27341
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 32700033edf67993b760448be923258a9c6571df01a5a9a149ab542b174fe0045746daaad0b921b541f48bb3e32a69df47eec6f334460fea67ddad19ed3a89c0
|
7
|
+
data.tar.gz: 0da29da22f9d467a3c50268e8e2097fe20b159ad94813726ed917f92214e7318f569e3cccc22d02661c07695a403af781a95576ce6359a877402ae6dbde82abc
|
@@ -1,65 +1,67 @@
|
|
1
|
-
require 'middleman-org/org_data'
|
2
|
-
require 'middleman-org/org_article'
|
3
|
-
require 'middleman-org/helpers'
|
4
|
-
|
5
1
|
module Middleman
|
6
2
|
class OrgExtension < ::Middleman::Extension
|
7
|
-
self.supports_multiple_instances = true
|
8
|
-
|
9
|
-
option :name, nil, 'Unique ID for telling multiple orgs apart'
|
10
|
-
option :layout, 'layout', 'article specific layout'
|
11
|
-
option :root, 'org', 'source folder for org files'
|
12
|
-
option :prefix, nil, 'prefix on destination and root path'
|
13
3
|
|
14
4
|
option :emacs, 'emacs', 'emacs executable'
|
15
5
|
option :load, nil, 'load elisp file'
|
6
|
+
option :defaults, {}, 'default values if the keys do not exsist'
|
7
|
+
option :alias, {}, 'alias'
|
16
8
|
|
17
|
-
|
18
|
-
attr_reader :name
|
19
|
-
|
20
|
-
self.defined_helpers = [Middleman::Org::Helpers]
|
9
|
+
# self.defined_helpers = [Middleman::Org::Helpers]
|
21
10
|
def initialize(app, options_hash = {}, &block)
|
22
11
|
# Call super to build options from the options_hash
|
23
12
|
super
|
24
13
|
|
25
14
|
# Require libraries only when activated
|
26
|
-
require 'emacs-ruby'
|
27
15
|
require 'org-ruby'
|
28
|
-
require 'middleman-org/org_data'
|
29
16
|
::Tilt.prefer(Tilt::OrgTemplate, 'org')
|
30
17
|
|
31
|
-
@name = options.name.to_sym if options.name
|
32
|
-
# options.root = File.join(options.prefix, options.root) if options.prefix
|
33
|
-
|
34
18
|
app.after_configuration do
|
35
19
|
template_extensions org: :html
|
36
20
|
if config[:org_engine] == :emacs_ruby
|
21
|
+
require 'emacs-ruby'
|
37
22
|
::Tilt.prefer(Tilt::EmacsRuby::OrgTemplate, 'org')
|
38
23
|
end
|
39
24
|
end
|
40
|
-
|
41
|
-
# set up your extension
|
42
|
-
# puts options.my_option
|
43
25
|
end
|
44
26
|
|
45
27
|
def after_configuration
|
46
|
-
|
47
|
-
|
28
|
+
::Middleman::Sitemap::Resource.send :include, OrgInstanceMethods
|
29
|
+
end
|
48
30
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
Time.zone = app.config[:time_zone] if app.config[:time_zone]
|
53
|
-
time_zone = Time.zone || 'UTC'
|
54
|
-
zone_default = Time.find_zone!(time_zone)
|
55
|
-
unless zone_default
|
56
|
-
raise 'Value assigned to time_zone not recognized.'
|
31
|
+
module OrgInstanceMethods
|
32
|
+
def in_buffer_setting
|
33
|
+
@in_buffer_setting ||= extract_ibs source_file
|
57
34
|
end
|
58
|
-
Time.zone_default = zone_default
|
59
35
|
|
60
|
-
|
61
|
-
|
62
|
-
|
36
|
+
def front_matter
|
37
|
+
# this code is from middleman-core
|
38
|
+
@enhanced_data ||= ::Middleman::Util.recursively_enhance(raw_data).freeze
|
39
|
+
end
|
63
40
|
|
41
|
+
def data
|
42
|
+
front_matter.merge(in_buffer_setting)
|
43
|
+
end
|
44
|
+
|
45
|
+
private
|
46
|
+
|
47
|
+
IN_BUFFER_SETTING_REGEXP = /^#\+(\w+):\s*(.*)$/
|
48
|
+
|
49
|
+
def extract_ibs(path)
|
50
|
+
ibs = {}
|
51
|
+
File.open(path, 'r') do |f|
|
52
|
+
f.each_line do |line|
|
53
|
+
if line =~ IN_BUFFER_SETTING_REGEXP
|
54
|
+
key = app.extensions[:org].options[:alias][$1.downcase] || $1.downcase
|
55
|
+
key = key.to_sym
|
56
|
+
ibs[key] = $2
|
57
|
+
end
|
58
|
+
end
|
59
|
+
end
|
60
|
+
app.extensions[:org].options[:defaults].each do |k, v|
|
61
|
+
ibs[k] = v unless ibs.has_key?(k)
|
62
|
+
end
|
63
|
+
ibs
|
64
|
+
end
|
65
|
+
end
|
64
66
|
end
|
65
67
|
end
|
data/middleman-org.gemspec
CHANGED
@@ -10,7 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ['dawnstar.hu@gmail.com']
|
11
11
|
s.homepage = 'http://github.com/xiaoxinghu/middleman-org'
|
12
12
|
s.summary = %q{org-mode extension for middleman}
|
13
|
-
s.description = %q{
|
13
|
+
s.description = %q{Use in buffer settings as front matter.}
|
14
14
|
s.files = `git ls-files`.split("\n")
|
15
15
|
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
16
16
|
s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: middleman-org
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Xiaoxing Hu
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-08-23 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: middleman-core
|
@@ -80,7 +80,7 @@ dependencies:
|
|
80
80
|
- - "~>"
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0.1'
|
83
|
-
description:
|
83
|
+
description: Use in buffer settings as front matter.
|
84
84
|
email:
|
85
85
|
- dawnstar.hu@gmail.com
|
86
86
|
executables: []
|
@@ -94,9 +94,6 @@ files:
|
|
94
94
|
- features/support/env.rb
|
95
95
|
- lib/middleman-org.rb
|
96
96
|
- lib/middleman-org/extension.rb
|
97
|
-
- lib/middleman-org/helpers.rb
|
98
|
-
- lib/middleman-org/org_article.rb
|
99
|
-
- lib/middleman-org/org_data.rb
|
100
97
|
- lib/middleman-org/version.rb
|
101
98
|
- lib/middleman_extension.rb
|
102
99
|
- middleman-org.gemspec
|
@@ -120,7 +117,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
120
117
|
version: '0'
|
121
118
|
requirements: []
|
122
119
|
rubyforge_project:
|
123
|
-
rubygems_version: 2.4.
|
120
|
+
rubygems_version: 2.4.8
|
124
121
|
signing_key:
|
125
122
|
specification_version: 4
|
126
123
|
summary: org-mode extension for middleman
|
@@ -1,52 +0,0 @@
|
|
1
|
-
module Middleman
|
2
|
-
module Org
|
3
|
-
def self.instances
|
4
|
-
@org_instances ||= {}
|
5
|
-
end
|
6
|
-
|
7
|
-
def self.instances=(v)
|
8
|
-
@org_instances = v
|
9
|
-
end
|
10
|
-
|
11
|
-
module Helpers
|
12
|
-
def self.included(base)
|
13
|
-
::Middleman::Org.instances = {}
|
14
|
-
end
|
15
|
-
|
16
|
-
def org_instances
|
17
|
-
::Middleman::Org.instances
|
18
|
-
end
|
19
|
-
|
20
|
-
def org_controller(org_name = nil)
|
21
|
-
# Warn if a non-existent org name provided
|
22
|
-
if org_name && !org_instances.keys.include?(org_name.to_sym)
|
23
|
-
fail "Non-existent org name provided: #{org_name}."
|
24
|
-
end
|
25
|
-
|
26
|
-
org_name ||= org_instances.keys.first
|
27
|
-
org_instances[org_name.to_sym]
|
28
|
-
end
|
29
|
-
|
30
|
-
def org_data(org_name = nil)
|
31
|
-
org_controller(org_name).data
|
32
|
-
end
|
33
|
-
|
34
|
-
def org_article?
|
35
|
-
!current_article.nil?
|
36
|
-
end
|
37
|
-
|
38
|
-
def current_article
|
39
|
-
article = current_resource
|
40
|
-
if article && article.is_a?(OrgArticle)
|
41
|
-
article
|
42
|
-
else
|
43
|
-
nil
|
44
|
-
end
|
45
|
-
end
|
46
|
-
|
47
|
-
def articles(org_name = nil)
|
48
|
-
org_data(org_name).articles
|
49
|
-
end
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
@@ -1,116 +0,0 @@
|
|
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
|
-
opts[:emacs] = org_options.emacs
|
46
|
-
opts[:load] = org_options.load
|
47
|
-
|
48
|
-
content = super(opts, locs, &block)
|
49
|
-
# testing
|
50
|
-
# content = export source_file
|
51
|
-
fix_links(content)
|
52
|
-
end
|
53
|
-
|
54
|
-
def fix_links(content)
|
55
|
-
html = ::Nokogiri::HTML(content)
|
56
|
-
html.xpath("//@src | //@href | //@poster").each do |attribute|
|
57
|
-
attribute.value = attribute.value.gsub(/^(.+)\.org$/, '\1.html')
|
58
|
-
end
|
59
|
-
html.to_s
|
60
|
-
end
|
61
|
-
|
62
|
-
def title
|
63
|
-
in_buffer_setting['TITLE'] || File.basename(source_file, '.*')
|
64
|
-
end
|
65
|
-
|
66
|
-
def keywords
|
67
|
-
article_keywords = in_buffer_setting['KEYWORDS']
|
68
|
-
return [] unless article_keywords
|
69
|
-
|
70
|
-
if article_keywords.is_a? String
|
71
|
-
article_keywords.split(' ').map(&:strip)
|
72
|
-
else
|
73
|
-
Array(article_keywords).map(&:to_s)
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
def description
|
78
|
-
in_buffer_setting['DESCRIPTION'] || 'no description'
|
79
|
-
end
|
80
|
-
|
81
|
-
def category
|
82
|
-
in_buffer_setting['CATEGORY'] || ''
|
83
|
-
end
|
84
|
-
|
85
|
-
def published?
|
86
|
-
in_buffer_setting['DATE'] || false
|
87
|
-
end
|
88
|
-
|
89
|
-
def body
|
90
|
-
render layout: false
|
91
|
-
end
|
92
|
-
|
93
|
-
def date
|
94
|
-
return @_date if @_date
|
95
|
-
|
96
|
-
return nil unless in_buffer_setting['DATE']
|
97
|
-
@_date = Date.parse in_buffer_setting['DATE']
|
98
|
-
|
99
|
-
# frontmatter_date = data['date']
|
100
|
-
|
101
|
-
# # First get the date from frontmatter
|
102
|
-
# if frontmatter_date.is_a? Time
|
103
|
-
# @_date = frontmatter_date.in_time_zone
|
104
|
-
# else
|
105
|
-
# @_date = Time.zone.parse(frontmatter_date.to_s)
|
106
|
-
# end
|
107
|
-
|
108
|
-
@_date
|
109
|
-
end
|
110
|
-
|
111
|
-
def slug
|
112
|
-
end
|
113
|
-
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
@@ -1,58 +0,0 @@
|
|
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
|
-
if options.prefix
|
32
|
-
resource.destination_path = resource
|
33
|
-
.path
|
34
|
-
.gsub(/^#{options.root}/,
|
35
|
-
options.prefix)
|
36
|
-
end
|
37
|
-
if File.extname(resource.source_file) == '.org'
|
38
|
-
article = convert_to_article resource
|
39
|
-
next unless publishable?(article)
|
40
|
-
@_articles << article
|
41
|
-
end
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
def publishable?(article)
|
46
|
-
@app.environment == :development || article.published?
|
47
|
-
end
|
48
|
-
|
49
|
-
def convert_to_article(resource)
|
50
|
-
return resource if resource.is_a?(OrgArticle)
|
51
|
-
resource.extend OrgArticle
|
52
|
-
resource.org_controller = controller
|
53
|
-
resource
|
54
|
-
end
|
55
|
-
|
56
|
-
end
|
57
|
-
end
|
58
|
-
end
|