hyde-page-js 0.3.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hyde-page-js.rb +34 -26
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 17a523c022d3eb4883130d9b143285e028f4f83fcfe3011f614ab0ec25a05aef
4
- data.tar.gz: b9b674f5042f528004838ab8e73a6f8840e70ae0bdb675f7991de420d715ff6f
3
+ metadata.gz: 71202952cbb7a6f848efb35f52b2567e0f5e71ff4c2bd03cb7900b646f76baf4
4
+ data.tar.gz: 89a466f9500aab52b11934ba3a7d4983727b8932322bb26142dd36e18c981188
5
5
  SHA512:
6
- metadata.gz: 2e5799de5113ea965a1d638bf7a69eba7946fc7133d5f5d8cf4d37a13090902d7b97a703f226c749c2c44f3bb78f578cc1a514c8e11d31ceecf2dabc08bd041f
7
- data.tar.gz: 203b8c566d58cebc526c8627425d6638b722003a4022b3af4d91126f64eba90696d289e808d3913fd7212f5fdb9e4c285a20131b2b313cb5166e8d2b12b4b7a1
6
+ metadata.gz: 15e8b455e09fc47ed4c174588c2bd53b3fd38eb83a79fdc94515f7af6737292f3d7be05349e8010cb312243fb76d309e62bdcfe5905265b796c1571f278eaa01
7
+ data.tar.gz: 3692c60d4d2a9b2511e19db565fc411281bf265465e1c5be0fd0c28d6a37ea2a64ccf61430ee455c47453b253307040cbec83687c2dbb2b80d0bc462bce11964
data/lib/hyde-page-js.rb CHANGED
@@ -2,14 +2,14 @@ require 'terser'
2
2
  require 'digest'
3
3
  require 'jekyll'
4
4
 
5
- Jekyll::Hooks.register :pages, :pre_render do |page, payload|
6
- Hyde::Page::Js.new(page).run
5
+ Jekyll::Hooks.register :pages, :post_init do |page, payload|
6
+ Hyde::Page::Js.new(page).run if page.instance_of? Jekyll::Page
7
7
  end
8
8
 
9
9
  module Hyde
10
10
  module Page
11
11
  class Js
12
- VERSION = "0.3.0"
12
+ VERSION = "0.3.2"
13
13
  end
14
14
 
15
15
  class GeneratedJsFile < Jekyll::StaticFile
@@ -65,34 +65,42 @@ module Hyde
65
65
  def run
66
66
  js = fetch_js(@page)
67
67
  layout = fetch_layout(fetch_layout_name(@page))
68
- results = parent_layout_js(layout, js).reverse
69
- return if results.empty?
68
+ js_groups = parent_layout_js(layout, js).reverse
69
+ return if js_groups.empty?
70
70
 
71
- lookup_name = names_to_key(results)
72
- return unless @site.data['_hyde_pages_cache'].fetch(lookup_name, nil).nil?
71
+ for group in js_groups
72
+ lookup_name = names_to_key(group)
73
+ cache_entry = @site.data['_hyde_pages_cache'].fetch(lookup_name, nil)
73
74
 
74
- data = concatenate_files(results)
75
- return if data == ""
75
+ if cache_entry.nil?
76
+ data = concatenate_files(group)
77
+ return if data == ""
76
78
 
77
- data = minify(data)
78
- return if data == ""
79
+ data = minify(data)
80
+ return if data == ""
79
81
 
80
- generated_file = generate_file(results, data)
82
+ generated_file = generate_file(group, data)
81
83
 
82
- # file already exists, so skip writing out the data to disk
83
- return unless @site.static_files.find { |static_file| static_file.name == generated_file.name }.nil?
84
+ # file already exists, so skip writing out the data to disk
85
+ return unless @site.static_files.find { |static_file| static_file.name == generated_file.name }.nil?
84
86
 
85
- # place file data into the new file
86
- generated_file.file_contents = data
87
+ # place file data into the new file
88
+ generated_file.file_contents = data
87
89
 
88
- # assign static file to list for jekyll to render
89
- @site.static_files << generated_file
90
+ # assign static file to list for jekyll to render
91
+ @site.static_files << generated_file
90
92
 
91
- # assign to site.data.js_files for liquid output
92
- add_to_urls(generated_file.url)
93
+ # add to cache
94
+ cache_entry = {
95
+ "url": generated_file.url,
96
+ "data": data
97
+ }
98
+ @site.data['_hyde_pages_cache'][lookup_name] = cache_entry
99
+ end
93
100
 
94
- # add to cache
95
- @site.data['_hyde_pages_cache'][lookup_name] = data
101
+ # assign to site.data.js_files for liquid output
102
+ add_to_urls(cache_entry.fetch(:url, nil)).compact
103
+ end
96
104
  end
97
105
 
98
106
  private
@@ -102,8 +110,8 @@ module Hyde
102
110
  end
103
111
 
104
112
  def add_to_urls(url)
105
- @site.data['js_files'] ||= []
106
- @site.data['js_files'].push(url)
113
+ @page.data['js_files'] ||= []
114
+ @page.data['js_files'].push(url)
107
115
  end
108
116
 
109
117
  def fetch_config
@@ -139,7 +147,7 @@ module Hyde
139
147
  end
140
148
 
141
149
  def fetch_js(obj_with_data, default = [])
142
- obj_with_data.data.fetch('js', []).reverse
150
+ [obj_with_data.data.fetch('js', [])]
143
151
  end
144
152
 
145
153
  def fetch_layout(layout_name, default = nil)
@@ -156,7 +164,7 @@ module Hyde
156
164
 
157
165
  def parent_layout_js(layout, js)
158
166
  if layout.nil?
159
- return js.uniq.compact
167
+ return js
160
168
  end
161
169
 
162
170
  layout_name = fetch_layout_name(layout)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hyde-page-js
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory Daynes