jekyll-org 1.1.0 → 1.1.1

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e8867c7504d6f7a0543a5f9964076c2bda053cccf1cc2064eaa2625faf1a68b9
4
- data.tar.gz: '087b4270646205c5c7a9129cc4a70df21c8904f8e44bbab81833a51af768435e'
3
+ metadata.gz: e1a71621e8118cb1ed2812a8925490ae238e3819aff428b35d251293fdc1ef5c
4
+ data.tar.gz: b95fd5972b6f8ce745a8dd9bc6b876952579b406e3df83e986cb59d677b80479
5
5
  SHA512:
6
- metadata.gz: 5125e60fff01be04c2023a0184a7700a66be2ab7b9ba8b72ebbcaf219233f46b932505335001d0c63a876270c19a23f28f931696bc27e0b340ff92c5d648850a
7
- data.tar.gz: 6233e0e5100393fba66ec0457b209ea9ae385e3213f543228f421eca9d14559e28bbb24f1b58ea738c04181c34bfff526a7bdaad55324be9175766baedff2baa
6
+ metadata.gz: 91ff1246f7f50cbc49582c3f045ef249195e55cb38c955b4af07d09268fb459edec4db31c43de6f98aeb810b20d50a80daf7d624472699c3dd24e5ad1a8b62fe
7
+ data.tar.gz: 5ec57394490ade2960cdc7b6de5c551b201246e1b98b6365da49d449297a9254bf67aa75177476a0aa67d7fd2a3455f9d60c41a78aeaaa1aa843728d3a218534
data/README.org CHANGED
@@ -53,6 +53,8 @@ plugins:
53
53
  - jekyll-org
54
54
  #+end_src
55
55
 
56
+ warning: If you are using Jekyll < 3.5.0 use the gems key instead of plugins.
57
+
56
58
  ** Usage
57
59
 
58
60
  Create a new file with =.org= extension in =_posts=, and write the post
@@ -69,6 +71,32 @@ with no lines:
69
71
  #+TAGS: jekyll org-mode "tag with spaces"
70
72
 
71
73
  This is a blog post about Jekyll and Org mode.
74
+
75
+ ** org-table demo
76
+
77
+ | a | b | c | d | e |
78
+ |---+---+---+---+---|
79
+ | 1 | 2 | 3 | 4 | 5 |
80
+
81
+ ** Liquid demo
82
+ #+liquid: enabled
83
+ #+foo: hello world
84
+ {{ page.foo }}
85
+
86
+ or
87
+
88
+ {{ site.time | date_to_xmlschema }}
89
+
90
+ ** Code highlighting
91
+ Jekyll-org also offers powerful support for code snippets:
92
+ #+begin_src ruby
93
+ def print_hi(name)
94
+ puts "Hi, #{name}"
95
+ end
96
+ print_hi('Tom')
97
+
98
+ #=> prints 'Hi, Tom' to STDOUT.
99
+ #+end_src
72
100
  #+END_EXAMPLE
73
101
 
74
102
  The value of =#+TAGS= is parsed into a list by splitting it on spaces,
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.1.0
1
+ 1.1.1
data/jekyll-org.gemspec CHANGED
@@ -2,16 +2,16 @@
2
2
  # DO NOT EDIT THIS FILE DIRECTLY
3
3
  # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
4
  # -*- encoding: utf-8 -*-
5
- # stub: jekyll-org 1.1.0 ruby lib
5
+ # stub: jekyll-org 1.1.1 ruby lib
6
6
 
7
7
  Gem::Specification.new do |s|
8
8
  s.name = "jekyll-org".freeze
9
- s.version = "1.1.0"
9
+ s.version = "1.1.1"
10
10
 
11
11
  s.required_rubygems_version = Gem::Requirement.new(">= 0".freeze) if s.respond_to? :required_rubygems_version=
12
12
  s.require_paths = ["lib".freeze]
13
13
  s.authors = ["eggcaker".freeze]
14
- s.date = "2019-12-11"
14
+ s.date = "2019-12-14"
15
15
  s.description = "So you want org-mode support for Jekyll. Write your _posts in org-mode, then add 'gems: [jekyll-org]' to your _config.yml. Thats it!".freeze
16
16
  s.email = "eggcaker@gmail.com".freeze
17
17
  s.extra_rdoc_files = [
@@ -27,6 +27,8 @@ Gem::Specification.new do |s|
27
27
  "VERSION",
28
28
  "jekyll-org.gemspec",
29
29
  "lib/jekyll-org.rb",
30
+ "lib/jekyll-org/converter.rb",
31
+ "lib/jekyll-org/utils.rb",
30
32
  "script/bootstrap",
31
33
  "script/cibuild",
32
34
  "script/console",
data/lib/jekyll-org.rb CHANGED
@@ -1,52 +1,21 @@
1
- require 'csv'
2
- require 'org-ruby'
3
-
4
1
  if Jekyll::VERSION < '3.0'
5
2
  raise Jekyll::FatalException, 'This version of jekyll-org is only compatible with Jekyll v3 and above.'
6
3
  end
7
4
 
8
- module Jekyll
9
- class OrgConverter < Converter
10
- safe true
11
- priority :low
12
-
13
- def matches(ext)
14
- ext =~ /org/i
15
- end
16
-
17
- def output_ext(ext)
18
- '.html'
19
- end
20
-
21
- def convert(content)
22
- content
23
- end
24
- end
5
+ require_relative './jekyll-org/converter'
25
6
 
7
+ module Jekyll
26
8
  module Filters
27
- def restify(input)
28
- site = @context.registers[:site]
29
- converter = site.find_converter_instance(Jekyll::OrgConverter)
9
+ def orgify(input)
10
+ site = @context.registers[:site]
11
+ converter = site.find_converter_instance(Jekyll::Converters::Org)
30
12
  converter.convert(input)
31
13
  end
32
14
  end
33
15
 
34
16
  module OrgDocument
35
17
  def org_file?
36
- extname.eql?(".org")
37
- end
38
-
39
- def site
40
- @site ||= Jekyll.configuration({})
41
- end
42
-
43
- def org_config
44
- site.config["org"] || Hash.new()
45
- end
46
-
47
- # see https://github.com/bdewey/org-ruby/blob/master/lib/org-ruby/parser.rb
48
- def _org_parser_options
49
- org_config.fetch("_org_parser_options", { markup_file: 'html.tags.yml' })
18
+ Jekyll::Converters::Org.matches(extname)
50
19
  end
51
20
 
52
21
  ## override: read file & parse YAML... in this case, don't parse YAML
@@ -55,66 +24,67 @@ module Jekyll
55
24
  return super unless org_file? # defer to default behaviour when not org file
56
25
 
57
26
  self.content = File.read(path, Utils.merged_file_read_opts(site, opts))
27
+ converter = site.find_converter_instance(Jekyll::Converters::Org)
28
+ parser, settings = converter.parse_org(self.content)
58
29
 
59
- org_text = Orgmode::Parser.new(content, _org_parser_options)
60
- @liquid_enabled = org_config.fetch("liquid", false)
61
-
62
- org_text.in_buffer_settings.each_pair do |key, value|
63
- # Remove #+TITLE from the buffer settings to avoid double exporting
64
- org_text.in_buffer_settings.delete(key) if key =~ /title/i
65
- org_assign_setting(key, value)
66
- end
30
+ @data = Utils.deep_merge_hashes(self.data, settings)
31
+ self.content = converter.actually_convert(parser)
32
+ end
33
+ end
67
34
 
68
- self.content = _org_buffer_handle_liquid(org_text)
35
+ module OrgPage
36
+ # Don't parse YAML blocks when working with an org file, parse it as
37
+ # an org file and then extracts the settings from there.
38
+ def read_yaml(base, name, opts = {})
39
+ extname = File.extname(name)
40
+ return super unless Jekyll::Converters::Org.matches(extname)
41
+ filename = File.join(base, name)
42
+
43
+ self.data ||= Hash.new()
44
+ self.content = File.read(@path || site.in_source_dir(base, name),
45
+ Utils.merged_file_read_opts(site, opts))
46
+ converter = site.find_converter_instance(Jekyll::Converters::Org)
47
+ parser, settings = converter.parse_org(self.content)
48
+
49
+ self.content = converter.actually_convert(parser)
50
+ self.data = Utils.deep_merge_hashes(self.data, settings)
69
51
  end
52
+ end
70
53
 
71
- def org_assign_setting(key, value)
72
- key = key.downcase
73
-
74
- case key
75
- when "liquid"
76
- value = _parse_boolean_value(value, "unknown LIQUID setting")
77
- @liquid_enabled = value unless value.nil?
78
- when "tags", "categories"
79
- # Parse a string of tags separated by spaces into a list.
80
- # Tags containing spaces can be wrapped in quotes,
81
- # e.g. '#+TAGS: foo "with spaces"'.
82
- #
83
- # The easiest way to do this is to use rubys builtin csv parser
84
- # and use spaces instead of commas as column separator.
85
- self.data[key] = CSV::parse_line(value, col_sep: ' ')
86
- else
87
- value_bool = _parse_boolean_value(value)
88
- self.data[key] = (value_bool.nil?) ? value : value_bool
54
+ class Collection
55
+ # make jekyll collections aside from _posts also convert org files.
56
+ def read
57
+ filtered_entries.each do |file_path|
58
+ full_path = collection_dir(file_path)
59
+ next if File.directory?(full_path)
60
+
61
+ if Utils.has_yaml_header?(full_path) ||
62
+ Jekyll::Converters::Org.matches_path(full_path)
63
+ read_document(full_path)
64
+ else
65
+ read_static_file(file_path, full_path)
66
+ end
89
67
  end
68
+
69
+ # TODO remove support for jekyll 3 on 4s release
70
+ (Jekyll::VERSION < '4.0') ? docs.sort! : sort_docs!
90
71
  end
72
+ end
91
73
 
92
- # format the org buffer text by enabling or disabling
93
- # the presence of liquid tags.
94
- def _org_buffer_handle_liquid(org_text)
95
- if @liquid_enabled
96
- org_text.to_html.gsub("&#8216;", "'").gsub("&#8217;", "'")
97
- else
98
- '{% raw %} ' + org_text.to_html + ' {% endraw %}'
99
- end
74
+ class Reader
75
+ def retrieve_org_files(dir, files)
76
+ retrieve_pages(dir, files)
100
77
  end
101
78
 
102
- @@truthy_regexps = [/enabled/, /yes/, /true/]
103
- @@falsy_regexps = [/disabled/, /no/, /false/]
104
-
105
- def _parse_boolean_value(value, error_msg=nil)
106
- case value.downcase
107
- when *@@truthy_regexps
108
- true
109
- when *@@falsy_regexps
110
- false
111
- else
112
- unless error_msg.nil?
113
- Jekyll.logger.warn("OrgDocument:", error_msg + ": #{value}")
114
- end
115
- end
79
+ # don't interpret org files without YAML as static files.
80
+ def retrieve_static_files(dir, files)
81
+ org_files, static_files = files.partition(&Jekyll::Converters::Org.method(:matches_path))
82
+
83
+ retrieve_org_files(dir, org_files) unless org_files.empty?
84
+ site.static_files.concat(StaticFileReader.new(site, dir).read(static_files))
116
85
  end
117
86
  end
118
87
  end
119
88
 
120
89
  Jekyll::Document.prepend(Jekyll::OrgDocument)
90
+ Jekyll::Page.prepend(Jekyll::OrgPage)
@@ -0,0 +1,125 @@
1
+ require 'csv'
2
+ require 'org-ruby'
3
+ require_relative './utils'
4
+
5
+ module Jekyll
6
+ module Converters
7
+ class Org < Converter
8
+ include Jekyll::OrgUtils
9
+
10
+ safe true
11
+ priority :low
12
+
13
+ # true if current file is an org file
14
+ def self.matches(ext)
15
+ ext =~ /org/i
16
+ end
17
+
18
+ # matches, but accepts complete path
19
+ def self.matches_path(path)
20
+ matches(File.extname(path))
21
+ end
22
+
23
+ def matches(ext)
24
+ self.class.matches ext
25
+ end
26
+
27
+ def output_ext(ext)
28
+ '.html'
29
+ end
30
+
31
+ # because by the time an org file reaches the
32
+ # converter... it will have already been converted.
33
+ def convert(content)
34
+ content
35
+ end
36
+
37
+ def actually_convert(content)
38
+ case content
39
+ when Orgmode::Parser
40
+ if liquid_enabled?(content)
41
+ content.to_html.gsub("&#8216;", "'").gsub("&#8217;", "'")
42
+ else
43
+ '{% raw %} ' + content.to_html + ' {% endraw %}'
44
+ end
45
+ else
46
+ parser, variables = parse_org(content)
47
+ convert(parser)
48
+ end
49
+ end
50
+
51
+ def parse_org(content)
52
+ parser = Orgmode::Parser.new(content, parser_options)
53
+ settings = { :liquid => org_config.fetch("liquid", false) }
54
+
55
+ parser.in_buffer_settings.each_pair do |key, value|
56
+ # Remove #+TITLE from the buffer settings to avoid double exporting
57
+ parser.in_buffer_settings.delete(key) if key =~ /title/i
58
+ assign_setting(key, value, settings)
59
+ end
60
+
61
+ return parser, settings
62
+ end
63
+
64
+ private
65
+
66
+ def config_liquid_enabled?
67
+ org_config.fetch("liquid", false)
68
+ end
69
+
70
+ def liquid_enabled?(parser)
71
+ tuple = parser.in_buffer_settings.each_pair.find do |key, _|
72
+ key =~ /liquid/i
73
+ end
74
+
75
+ if tuple.nil?
76
+ config_liquid_enabled? # default value, as per config
77
+ else
78
+ _parse_boolean(tuple[1], "unknown LIQUID setting")
79
+ end
80
+ end
81
+
82
+ # see https://github.com/bdewey/org-ruby/blob/master/lib/org-ruby/parser.rb
83
+ def parser_options
84
+ org_config.fetch("parser_options", { markup_file: 'html.tags.yml' })
85
+ end
86
+
87
+ def assign_setting(key, value, settings)
88
+ key = key.downcase
89
+
90
+ case key
91
+ when "liquid"
92
+ value = _parse_boolean(value, "unknown LIQUID setting")
93
+ settings[:liquid] = value unless value.nil?
94
+ when "tags", "categories"
95
+ # Parse a string of tags separated by spaces into a list.
96
+ # Tags containing spaces can be wrapped in quotes,
97
+ # e.g. '#+TAGS: foo "with spaces"'.
98
+ #
99
+ # The easiest way to do this is to use rubys builtin csv parser
100
+ # and use spaces instead of commas as column separator.
101
+ settings[key] = CSV::parse_line(value, col_sep: ' ')
102
+ else
103
+ value_bool = _parse_boolean(value)
104
+ settings[key] = (value_bool.nil?) ? value : value_bool
105
+ end
106
+ end
107
+
108
+ @@truthy_regexps = [/enabled/, /yes/, /true/]
109
+ @@falsy_regexps = [/disabled/, /no/, /false/]
110
+
111
+ def _parse_boolean(value, error_msg=nil)
112
+ case value.downcase
113
+ when *@@truthy_regexps
114
+ true
115
+ when *@@falsy_regexps
116
+ false
117
+ else
118
+ unless error_msg.nil?
119
+ Jekyll.logger.warn("OrgDocument:", error_msg + ": #{value}")
120
+ end
121
+ end
122
+ end
123
+ end
124
+ end
125
+ end
@@ -0,0 +1,19 @@
1
+ module Jekyll
2
+ module OrgUtils
3
+ def self.site
4
+ @@site ||= Jekyll.configuration({})
5
+ end
6
+
7
+ def self.org_config
8
+ site["org"] || Hash.new()
9
+ end
10
+
11
+ def site
12
+ OrgUtils.site
13
+ end
14
+
15
+ def org_config
16
+ OrgUtils.org_config
17
+ end
18
+ end
19
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-org
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - eggcaker
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-12-11 00:00:00.000000000 Z
11
+ date: 2019-12-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: org-ruby
@@ -153,6 +153,8 @@ files:
153
153
  - VERSION
154
154
  - jekyll-org.gemspec
155
155
  - lib/jekyll-org.rb
156
+ - lib/jekyll-org/converter.rb
157
+ - lib/jekyll-org/utils.rb
156
158
  - script/bootstrap
157
159
  - script/cibuild
158
160
  - script/console