jekyll-gdocfilter 0.1.1 → 0.1.2

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: 691d15c67635094f9f17bc10f9ca3e0a8863e3534f313032ed92dc09414a3951
4
- data.tar.gz: 3924781db4b1a46668e32dd06ab469997ed6800a6da0a1e0449973d60758da19
3
+ metadata.gz: 12544ae2377380a82f397663b3af1af168adb1b38bb24fa26e379b479174082b
4
+ data.tar.gz: '069975564a087ea50af0170eae98adcfe26c118e86fa51489d5d3683967ba5a8'
5
5
  SHA512:
6
- metadata.gz: ba60208effacc68530a7aaef10514e541a555c0e44ad0873f79d2c6b266160e694f861f9c1d4889307aee83ac5e62f0532b1ab4bd42cb1edacb8a62692f7f3a6
7
- data.tar.gz: e6db91665907ea9c239f37721504ad1456d1b0f240504372e6cbab2bdaddc0cbb3642b47d1d11e717abb0d66ee3ba205eb3abd39f8a07a4fcd584d1bbfc25f17
6
+ metadata.gz: c0008fffdcd51b1bd186bf9d445a62179e9668f8520c299c8694db4fedd3044532033e7961069ede907f0f9e7f293554521618803058e597108868486de63830
7
+ data.tar.gz: bd9109d4350ad4e5b0fef44aa31809fbb9061918832a86e261fe9949df1fb7097a5d39d9f9204a3808b62b9bbe3e2dd7a0f7017bcad53450a00850b30e691ad3
data/.rubocop.yml CHANGED
@@ -1,5 +1,10 @@
1
1
  AllCops:
2
- TargetRubyVersion: 2.4
2
+ TargetRubyVersion: 2.5
3
+ NewCops: enable
4
+ SuggestExtensions: false
5
+ Exclude:
6
+ - 'example/**/*'
7
+ - 'vendor/**/*'
3
8
 
4
9
  Style/StringLiterals:
5
10
  Enabled: true
data/CHANGELOG.md CHANGED
@@ -1,5 +1,12 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ### [0.1.2](https://www.github.com/tippingpointuk/jekyll-gdocfilter/compare/v0.1.1...v0.1.2) (2022-11-14)
4
+
5
+
6
+ ### Bug Fixes
7
+
8
+ * minor bug fixes ([cf900ee](https://www.github.com/tippingpointuk/jekyll-gdocfilter/commit/cf900ee2e63994789ec0e6f8567d31a953bfc3f4))
9
+
3
10
  ### [0.1.1](https://www.github.com/tippingpointuk/jekyll-gdocfilter/compare/v0.1.0...v0.1.1) (2022-04-01)
4
11
 
5
12
 
data/Gemfile.lock ADDED
@@ -0,0 +1,126 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ jekyll-gdocfilter (0.1.1)
5
+ css_parser (= 1.11.0)
6
+ jekyll (>= 3.7, < 5.0)
7
+ nokogiri (>= 1.11.0, <= 1.13.3)
8
+ open-uri (= 0.2.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ addressable (2.8.0)
14
+ public_suffix (>= 2.0.2, < 5.0)
15
+ ast (2.4.2)
16
+ colorator (1.1.0)
17
+ concurrent-ruby (1.1.10)
18
+ css_parser (1.11.0)
19
+ addressable
20
+ date (3.2.2)
21
+ diff-lcs (1.5.0)
22
+ em-websocket (0.5.3)
23
+ eventmachine (>= 0.12.9)
24
+ http_parser.rb (~> 0)
25
+ eventmachine (1.2.7)
26
+ ffi (1.15.5)
27
+ forwardable-extended (2.6.0)
28
+ http_parser.rb (0.8.0)
29
+ i18n (1.10.0)
30
+ concurrent-ruby (~> 1.0)
31
+ jekyll (4.2.2)
32
+ addressable (~> 2.4)
33
+ colorator (~> 1.0)
34
+ em-websocket (~> 0.5)
35
+ i18n (~> 1.0)
36
+ jekyll-sass-converter (~> 2.0)
37
+ jekyll-watch (~> 2.0)
38
+ kramdown (~> 2.3)
39
+ kramdown-parser-gfm (~> 1.0)
40
+ liquid (~> 4.0)
41
+ mercenary (~> 0.4.0)
42
+ pathutil (~> 0.9)
43
+ rouge (~> 3.0)
44
+ safe_yaml (~> 1.0)
45
+ terminal-table (~> 2.0)
46
+ jekyll-sass-converter (2.2.0)
47
+ sassc (> 2.0.1, < 3.0)
48
+ jekyll-watch (2.2.1)
49
+ listen (~> 3.0)
50
+ kramdown (2.3.2)
51
+ rexml
52
+ kramdown-parser-gfm (1.1.0)
53
+ kramdown (~> 2.0)
54
+ liquid (4.0.3)
55
+ listen (3.7.1)
56
+ rb-fsevent (~> 0.10, >= 0.10.3)
57
+ rb-inotify (~> 0.9, >= 0.9.10)
58
+ mercenary (0.4.0)
59
+ nokogiri (1.13.3-x86_64-linux)
60
+ racc (~> 1.4)
61
+ open-uri (0.2.0)
62
+ stringio
63
+ time
64
+ uri
65
+ parallel (1.22.1)
66
+ parser (3.1.1.0)
67
+ ast (~> 2.4.1)
68
+ pathutil (0.16.2)
69
+ forwardable-extended (~> 2.6)
70
+ public_suffix (4.0.6)
71
+ racc (1.6.0)
72
+ rainbow (3.1.1)
73
+ rake (13.0.6)
74
+ rb-fsevent (0.11.1)
75
+ rb-inotify (0.10.1)
76
+ ffi (~> 1.0)
77
+ regexp_parser (2.2.1)
78
+ rexml (3.2.5)
79
+ rouge (3.28.0)
80
+ rspec (3.11.0)
81
+ rspec-core (~> 3.11.0)
82
+ rspec-expectations (~> 3.11.0)
83
+ rspec-mocks (~> 3.11.0)
84
+ rspec-core (3.11.0)
85
+ rspec-support (~> 3.11.0)
86
+ rspec-expectations (3.11.0)
87
+ diff-lcs (>= 1.2.0, < 2.0)
88
+ rspec-support (~> 3.11.0)
89
+ rspec-mocks (3.11.1)
90
+ diff-lcs (>= 1.2.0, < 2.0)
91
+ rspec-support (~> 3.11.0)
92
+ rspec-support (3.11.0)
93
+ rubocop (1.26.1)
94
+ parallel (~> 1.10)
95
+ parser (>= 3.1.0.0)
96
+ rainbow (>= 2.2.2, < 4.0)
97
+ regexp_parser (>= 1.8, < 3.0)
98
+ rexml
99
+ rubocop-ast (>= 1.16.0, < 2.0)
100
+ ruby-progressbar (~> 1.7)
101
+ unicode-display_width (>= 1.4.0, < 3.0)
102
+ rubocop-ast (1.16.0)
103
+ parser (>= 3.1.1.0)
104
+ ruby-progressbar (1.11.0)
105
+ safe_yaml (1.0.5)
106
+ sassc (2.4.0)
107
+ ffi (~> 1.9)
108
+ stringio (3.0.1)
109
+ terminal-table (2.0.0)
110
+ unicode-display_width (~> 1.1, >= 1.1.1)
111
+ time (0.2.0)
112
+ date
113
+ unicode-display_width (1.8.0)
114
+ uri (0.11.0)
115
+
116
+ PLATFORMS
117
+ x86_64-linux
118
+
119
+ DEPENDENCIES
120
+ jekyll-gdocfilter!
121
+ rake (~> 13.0)
122
+ rspec (~> 3.0)
123
+ rubocop (~> 1.7)
124
+
125
+ BUNDLED WITH
126
+ 2.2.21
data/example/Gemfile CHANGED
@@ -16,7 +16,7 @@ gem "minima", "~> 2.5"
16
16
  # If you have any plugins, put them here!
17
17
  group :jekyll_plugins do
18
18
  gem "jekyll-feed", "~> 0.12"
19
- gem "jekyll-gdocfilter", path: "../"
19
+ gem "jekyll-gdocfilter"
20
20
  end
21
21
 
22
22
  # Windows and JRuby does not include zoneinfo files, so bundle the tzinfo-data gem
data/example/Gemfile.lock CHANGED
@@ -1,12 +1,3 @@
1
- PATH
2
- remote: ..
3
- specs:
4
- jekyll-gdocfilter (0.1.0)
5
- css_parser (= 1.11.0)
6
- jekyll (>= 3.7, < 5.0)
7
- nokogiri (>= 1.11.0, <= 1.13.3)
8
- open-uri (= 0.2.0)
9
-
10
1
  GEM
11
2
  remote: https://rubygems.org/
12
3
  specs:
@@ -43,6 +34,11 @@ GEM
43
34
  terminal-table (~> 2.0)
44
35
  jekyll-feed (0.16.0)
45
36
  jekyll (>= 3.7, < 5.0)
37
+ jekyll-gdocfilter (0.1.1)
38
+ css_parser (= 1.11.0)
39
+ jekyll (>= 3.7, < 5.0)
40
+ nokogiri (>= 1.11.0, <= 1.13.3)
41
+ open-uri (= 0.2.0)
46
42
  jekyll-sass-converter (2.2.0)
47
43
  sassc (> 2.0.1, < 3.0)
48
44
  jekyll-seo-tag (2.8.0)
@@ -94,7 +90,7 @@ PLATFORMS
94
90
  DEPENDENCIES
95
91
  jekyll (~> 4.2.0)
96
92
  jekyll-feed (~> 0.12)
97
- jekyll-gdocfilter!
93
+ jekyll-gdocfilter
98
94
  minima (~> 2.5)
99
95
  tzinfo (~> 1.2)
100
96
  tzinfo-data
@@ -13,7 +13,7 @@ Gem::Specification.new do |spec|
13
13
  and returns HTML with basic styling to put on your pages"
14
14
  spec.homepage = "https://github.com/tippingpointuk/jekyll-gdocfilter"
15
15
  spec.license = "MIT"
16
- spec.required_ruby_version = ">= 2.4.0"
16
+ spec.required_ruby_version = ">= 2.5.0"
17
17
 
18
18
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
19
19
 
@@ -31,11 +31,12 @@ Gem::Specification.new do |spec|
31
31
  spec.require_paths = ["lib"]
32
32
 
33
33
  # Uncomment to register a new dependency of your gem
34
+ spec.add_dependency "css_parser", "1.11.0"
34
35
  spec.add_dependency "jekyll", ">= 3.7", "< 5.0"
35
36
  spec.add_dependency "nokogiri", ">=1.11.0", "<=1.13.3"
36
- spec.add_dependency "css_parser", "1.11.0"
37
37
  spec.add_dependency "open-uri", "0.2.0"
38
38
 
39
39
  # For more information and examples about making a new gem, checkout our
40
40
  # guide at: https://bundler.io/guides/creating_gem.html
41
+ spec.metadata["rubygems_mfa_required"] = "true"
41
42
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Jekyll
4
4
  module Gdocfilter
5
- VERSION = "0.1.1"
5
+ VERSION = "0.1.2"
6
6
  end
7
7
  end
@@ -1,64 +1,63 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative "gdocfilter/version"
4
- require 'nokogiri'
5
- require 'open-uri'
6
- require 'css_parser'
4
+ require "nokogiri"
5
+ require "open-uri"
6
+ require "css_parser"
7
+ require "liquid"
7
8
 
8
9
  module Jekyll
10
+ ##
11
+ # Parses a google doc link to neatly embedable html,
12
+ # using the +google_doc+ method.
9
13
  module Gdocfilter
10
14
  class Error < StandardError; end
11
- ##
12
- # Parses a google doc link to neatly embedable html,
13
- # using the +google_doc+ method.
15
+
16
+ def get_query_from_link(link)
17
+ return unless link
18
+
19
+ href = URI(link)
20
+ return link unless href.query
21
+
22
+ query = CGI.parse(href.query)
23
+ return href unless query["q"][0]
24
+
25
+ query["q"][0]
26
+ end
14
27
 
15
28
  def replace_links(html)
16
29
  # Removes the google.com proxy from links in the doc
17
- html.css('a').each do |link|
18
- href = URI(link.attributes["href"].value)
19
- next unless href.query
20
- query = CGI.parse(href.query)
21
- next unless query['q'][0]
22
- link.attributes['href'].value = query['q'][0]
30
+ html.css("a").each do |link|
31
+ next unless link.attributes["href"]
32
+
33
+ href = link.attributes["href"].value
34
+ link.attributes["href"].value = get_query_from_link(href)
23
35
  end
24
36
  @html = html
25
37
  end
38
+
26
39
  def reduce_styles(css)
27
40
  # Extract basic styling from the <style> tag at top of document
28
41
  # ie. bold, colours
29
42
  # But not any of the layout/spacing/font-type styles
30
- allowed_rules = [
31
- 'font-weight',
32
- # 'color',
33
- 'font-style',
34
- 'text-decoration'
35
- ]
36
-
43
+ allowed_rules = %w[font-weight font-style text-decoration]
37
44
  parser_css.add_block! css
38
-
39
45
  parser_css.each_rule_set do |rule_set|
40
- # puts rule_set['declarations']['declarations']
41
46
  rule_set.each_declaration do |d|
42
47
  rule_set.remove_declaration! d unless allowed_rules.include? d
43
48
  end
44
49
  end
45
-
46
- # parser_css.each_selector do |selector, declarations, specificity|
47
- # next unless selector =~ /^[\d\w\s\#\.\-]*$/ # Check if is real selector
48
- #
49
- #
50
- # end
51
-
52
50
  @parser_css
53
51
  end
54
52
 
55
53
  def inline_styles(html)
56
- css = reduce_styles html.css('style').inner_html
57
- css.each_selector do |selector, declarations, specificity|
58
- next unless selector =~ /^[\d\w\s\#\.\-]*$/ # Check if is real selector
54
+ css = reduce_styles html.css("style").inner_html
55
+ css.each_selector do |selector, declarations, _specificity|
56
+ next unless selector =~ /^[\d\w\s\#.\-]*$/ # Check if is real selector
57
+
59
58
  elements = html.css(selector)
60
59
  elements.each do |e|
61
- e['style'] = [e["style"], declarations].compact.join(" ")
60
+ e["style"] = [e["style"], declarations].compact.join(" ")
62
61
  end
63
62
  end
64
63
  @html = html
@@ -69,15 +68,11 @@ module Jekyll
69
68
  # Downsize headings by 1
70
69
  (5).downto(1) do |n|
71
70
  heading = html.at_css "h#{n}"
72
- if heading
73
- heading.name = "h#{n + 1}"
74
- end
71
+ heading.name = "h#{n + 1}" if heading
75
72
  end
76
73
 
77
- title = html.at_css 'p.title'
78
- if title
79
- title.name = 'h1'
80
- end
74
+ title = html.at_css "p.title"
75
+ title.name = "h1" if title
81
76
 
82
77
  @html = html
83
78
  end
@@ -86,17 +81,40 @@ module Jekyll
86
81
  @parser_css ||= CssParser::Parser.new
87
82
  end
88
83
 
89
- def google_doc(link)
90
- # TODO:
91
- # * Properly nest lists
84
+ def get_html(link)
92
85
  ids = /[-\w]{25,}/.match(link)
93
86
  return unless ids
94
- f = URI.open "https://docs.google.com/feeds/download/documents/export/Export?id=#{ids[0]}&exportFormat=html"
87
+
88
+ @url = URI(link)
89
+ return unless @url.host == "docs.google.com"
90
+
91
+ link = "https://docs.google.com/feeds/download/documents/export/Export?id=#{ids[0]}&exportFormat=html"
92
+
93
+ f = get_file(link)
94
+ return unless f
95
+
95
96
  @html = Nokogiri::HTML.parse f
97
+ end
98
+
99
+ def get_file(url)
100
+ begin
101
+ f = URI.open url
102
+ rescue OpenURI::HTTPError
103
+ return
104
+ end
105
+ return unless f.status[1] == "OK"
106
+
107
+ f
108
+ end
109
+
110
+ def google_doc(link)
111
+ return unless get_html(link)
112
+
96
113
  replace_links @html
97
114
  inline_styles @html
98
115
  convert_headings @html
99
- @html.css('body').inner_html
116
+ # TODO: Properly nest lists
117
+ @html.css("body").inner_html
100
118
  end
101
119
  end
102
120
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jekyll-gdocfilter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - joe-irving
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2022-04-01 00:00:00.000000000 Z
11
+ date: 2022-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: css_parser
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '='
18
+ - !ruby/object:Gem::Version
19
+ version: 1.11.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.11.0
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: jekyll
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -50,20 +64,6 @@ dependencies:
50
64
  - - "<="
51
65
  - !ruby/object:Gem::Version
52
66
  version: 1.13.3
53
- - !ruby/object:Gem::Dependency
54
- name: css_parser
55
- requirement: !ruby/object:Gem::Requirement
56
- requirements:
57
- - - '='
58
- - !ruby/object:Gem::Version
59
- version: 1.11.0
60
- type: :runtime
61
- prerelease: false
62
- version_requirements: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - '='
65
- - !ruby/object:Gem::Version
66
- version: 1.11.0
67
67
  - !ruby/object:Gem::Dependency
68
68
  name: open-uri
69
69
  requirement: !ruby/object:Gem::Requirement
@@ -95,6 +95,7 @@ files:
95
95
  - CHANGELOG.md
96
96
  - CODE_OF_CONDUCT.md
97
97
  - Gemfile
98
+ - Gemfile.lock
98
99
  - LICENSE.txt
99
100
  - README.md
100
101
  - Rakefile
@@ -118,6 +119,7 @@ metadata:
118
119
  homepage_uri: https://github.com/tippingpointuk/jekyll-gdocfilter
119
120
  source_code_uri: https://github.com/tippingpointuk/jekyll-gdocfilter/
120
121
  changelog_uri: https://github.com/tippingpointuk/jekyll-gdocfilter/CHANGELOG.md
122
+ rubygems_mfa_required: 'true'
121
123
  post_install_message:
122
124
  rdoc_options: []
123
125
  require_paths:
@@ -126,14 +128,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
126
128
  requirements:
127
129
  - - ">="
128
130
  - !ruby/object:Gem::Version
129
- version: 2.4.0
131
+ version: 2.5.0
130
132
  required_rubygems_version: !ruby/object:Gem::Requirement
131
133
  requirements:
132
134
  - - ">="
133
135
  - !ruby/object:Gem::Version
134
136
  version: '0'
135
137
  requirements: []
136
- rubygems_version: 3.2.3
138
+ rubygems_version: 3.1.2
137
139
  signing_key:
138
140
  specification_version: 4
139
141
  summary: A simple filter to turn a Google Doc into readable HTML