grover 0.3.1 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c7d5ea905a539c2326c8f58e7bade296648fa300
4
- data.tar.gz: c87e18907dab9181629998302b3e88b90c064f58
3
+ metadata.gz: 7c6a07a0ade8c23210286b3501d87f9634c7f66d
4
+ data.tar.gz: 149a9096b926444174cd1c4ef1b2425bac25ea9f
5
5
  SHA512:
6
- metadata.gz: 5490e256b29f0684a5c41ea0cdb193347ef9b01eb69e35d52d03302a6d49b4fb9aeb3e3dd7ea77b69bff789fa1491f0c71a6db08bc72b189a7b72daf6cb92a79
7
- data.tar.gz: fe20dafde8aa7987f09e60691d9dcfafab7af3366ea6e0892971a4e9b3f29b1d8d9cb37ef04f3fd33d152ad40b1771af243e08000c3181a2120d7f35648dc672
6
+ metadata.gz: 6ba6d666daec6b31fabb7484ad74c00787b18184ccb583c6c71fc923c0ac7ee6b9557d45a06a89e0627426af2ad11c2d886970a1eb7776f976d799d8f9280108
7
+ data.tar.gz: a7d4fd2f0b140f37b3c3cb5f7d33abcfb67cbe414c6eb79caf9c1ac10f954dfc46f7233e5df04ff3b946a6b1bd6433d1d74ca2bc1713246d4b5bf921ce02f338
@@ -3,10 +3,11 @@ class Grover
3
3
  # Configuration of the options for Grover HTML to PDF conversion
4
4
  #
5
5
  class Configuration
6
- attr_accessor :options
6
+ attr_accessor :options, :meta_tag_prefix
7
7
 
8
8
  def initialize
9
9
  @options = {}
10
+ @meta_tag_prefix = 'grover-'
10
11
  end
11
12
  end
12
13
  end
data/lib/grover/utils.rb CHANGED
@@ -30,6 +30,19 @@ class Grover
30
30
  inline ? string.delete("\n") : string
31
31
  end
32
32
 
33
+ #
34
+ # Assign value to a hash using an array of keys to traverse
35
+ #
36
+ def self.deep_assign(hash, keys, value)
37
+ if keys.length == 1
38
+ hash[keys.first] = value
39
+ else
40
+ key = keys.shift
41
+ hash[key] ||= {}
42
+ deep_assign hash[key], keys, value
43
+ end
44
+ end
45
+
33
46
  #
34
47
  # Recursively normalizes hash objects with camelized string keys
35
48
  #
@@ -1,3 +1,3 @@
1
1
  class Grover
2
- VERSION = '0.3.1'.freeze
2
+ VERSION = '0.4.1'.freeze
3
3
  end
data/lib/grover.rb CHANGED
@@ -49,6 +49,14 @@ class Grover
49
49
  end
50
50
  private_constant :Processor
51
51
 
52
+ DISPLAY_URL_PLACEHOLDER = '{{display_url}}'.freeze
53
+
54
+ DEFAULT_HEADER_TEMPLATE = "<div class='date text left'></div><div class='title text center'></div>".freeze
55
+ DEFAULT_FOOTER_TEMPLATE = Utils.strip_heredoc(<<-HTML).freeze
56
+ <div class='text left grow'>#{DISPLAY_URL_PLACEHOLDER}</div>
57
+ <div class='text right'><span class='pageNumber'></span>/<span class='totalPages'></span></div>
58
+ HTML
59
+
52
60
  #
53
61
  # @param [String] url URL of the page to convert
54
62
  # @param [Hash] options Optional parameters to pass to PDF processor
@@ -120,14 +128,28 @@ class Grover
120
128
 
121
129
  def normalized_options(path)
122
130
  options = Utils.normalize_object options_with_template_fix
131
+ options.merge! meta_options unless url_source?
123
132
  options['path'] = path if path
124
133
  options
125
134
  end
126
135
 
127
- DISPLAY_URL_PLACEHOLDER = '{{display_url}}'.freeze
136
+ #
137
+ # Extract out options from meta tags in the source - based on code from PDFKit project
138
+ #
139
+ def meta_options
140
+ meta_opts = {}
128
141
 
129
- DEFAULT_FOOTER_TEMPLATE = Utils.strip_heredoc(<<-HTML).freeze
130
- <div class='text left grow'>#{DISPLAY_URL_PLACEHOLDER}</div>
131
- <div class='text right'><span class='pageNumber'></span>/<span class='totalPages'></span></div>
132
- HTML
142
+ @url.scan(/<meta [^>]*>/) do |meta|
143
+ tag_name = meta[/name=["']#{Grover.configuration.meta_tag_prefix}([a-z_-]+)["']/, 1]
144
+ next if tag_name.nil?
145
+
146
+ Utils.deep_assign meta_opts, tag_name.split('-'), meta[/content=["']([^"']+)["']/, 1]
147
+ end
148
+
149
+ meta_opts
150
+ end
151
+
152
+ def url_source?
153
+ @url.match(/^http/i)
154
+ end
133
155
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grover
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.4.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Andrew Bromwich
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-08-24 00:00:00.000000000 Z
11
+ date: 2018-09-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: schmooze