impression 0.3 → 0.4

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
  SHA256:
3
- metadata.gz: 5644ebb122c166a8a5579a950b3e64fde5d3d332eea8299aa4c4023af8b85cb6
4
- data.tar.gz: b89065d1cd8c14d5ddad28f1fc3ff90cc48d43354698e339715f3b6d172af671
3
+ metadata.gz: f310190c6415f14cdc24e4ab871dee51122a148292b778d6fc4679dafa03b10c
4
+ data.tar.gz: 302dd60dea184497508d7200354bf230835e0e84768ef6f5e5f5ee1e8ee27416
5
5
  SHA512:
6
- metadata.gz: 45ab7c1f4e3c9f920175acc8bce2417932571ceca8946cf1fd0b784a6280413514587bc998d467808023c56e054a0edc2c821e6dc700289a4a02f4e2372dfe05
7
- data.tar.gz: d3b57e4089e0473e508f5a67c52db12be7a62850897bc79a27871b4ea7a3d2b3b3062f214980a98d5e842033b62496ae9024416c37b00ca05b527b01c088b53e
6
+ metadata.gz: dc1469936dd52810143d48ce608335a96b2fcfac8187d481c6df031bc4b3bc9d22ef41a3532660fb0826973dd356ef7ba7f181fdd1ac8ea8be31bc080b99013c
7
+ data.tar.gz: 89294842887b2da78309bb2c5cb3472123f363a315e2b22d9dcac67753e6008926374222895a40f373738c6dbdb964752873d459fac942cd99a68eafb4e1fd11
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ # 0.4 2022-01-19
2
+
3
+ - Remove deprecated Pages code (#6)
4
+
1
5
  # 0.3 2022-01-19
2
6
 
3
7
  - Implement basic Jamstack resource (#5)
data/Gemfile.lock CHANGED
@@ -1,14 +1,11 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- impression (0.3)
5
- kramdown (~> 2.3.0)
6
- kramdown-parser-gfm (~> 1.1.0)
4
+ impression (0.4)
7
5
  modulation (~> 1.1)
8
6
  papercraft (~> 0.14)
9
7
  polyphony (~> 0.73.1)
10
8
  qeweney (~> 0.15)
11
- rouge (~> 3.26.0)
12
9
  tipi (~> 0.45)
13
10
 
14
11
  GEM
data/impression.gemspec CHANGED
@@ -10,7 +10,10 @@ Gem::Specification.new do |s|
10
10
  s.files = `git ls-files`.split
11
11
  s.homepage = 'http://github.com/digital-fabric/impression'
12
12
  s.metadata = {
13
- "source_code_uri" => "https://github.com/digital-fabric/impression"
13
+ "source_code_uri" => "https://github.com/digital-fabric/impression",
14
+ "documentation_uri" => "https://www.rubydoc.info/gems/impression",
15
+ "homepage_uri" => "https://github.com/digital-fabric/impression",
16
+ "changelog_uri" => "https://github.com/digital-fabric/impression/blob/master/CHANGELOG.md"
14
17
  }
15
18
  s.rdoc_options = ["--title", "impression", "--main", "README.md"]
16
19
  s.extra_rdoc_files = ["README.md"]
@@ -23,10 +26,6 @@ Gem::Specification.new do |s|
23
26
  s.add_runtime_dependency 'tipi', '~>0.45'
24
27
  s.add_runtime_dependency 'qeweney', '~>0.15'
25
28
 
26
- s.add_runtime_dependency 'kramdown', '~>2.3.0'
27
- s.add_runtime_dependency 'rouge', '~>3.26.0'
28
- s.add_runtime_dependency 'kramdown-parser-gfm', '~>1.1.0'
29
-
30
29
  # s.add_runtime_dependency 'rb-inotify', '~>0.10.1'
31
30
  s.add_runtime_dependency 'papercraft', '~>0.14'
32
31
  s.add_runtime_dependency 'modulation', '~>1.1'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Impression
4
- VERSION = '0.3'
4
+ VERSION = '0.4'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: impression
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sharon Rosner
@@ -52,48 +52,6 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0.15'
55
- - !ruby/object:Gem::Dependency
56
- name: kramdown
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - "~>"
60
- - !ruby/object:Gem::Version
61
- version: 2.3.0
62
- type: :runtime
63
- prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
66
- - - "~>"
67
- - !ruby/object:Gem::Version
68
- version: 2.3.0
69
- - !ruby/object:Gem::Dependency
70
- name: rouge
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - "~>"
74
- - !ruby/object:Gem::Version
75
- version: 3.26.0
76
- type: :runtime
77
- prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - "~>"
81
- - !ruby/object:Gem::Version
82
- version: 3.26.0
83
- - !ruby/object:Gem::Dependency
84
- name: kramdown-parser-gfm
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
87
- - - "~>"
88
- - !ruby/object:Gem::Version
89
- version: 1.1.0
90
- type: :runtime
91
- prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - "~>"
95
- - !ruby/object:Gem::Version
96
- version: 1.1.0
97
55
  - !ruby/object:Gem::Dependency
98
56
  name: papercraft
99
57
  requirement: !ruby/object:Gem::Requirement
@@ -192,7 +150,6 @@ files:
192
150
  - lib/impression/file_tree.rb
193
151
  - lib/impression/file_watcher.rb
194
152
  - lib/impression/jamstack.rb
195
- - lib/impression/pages.rb
196
153
  - lib/impression/request_extensions.rb
197
154
  - lib/impression/request_extensions/responses.rb
198
155
  - lib/impression/request_extensions/routing.rb
@@ -222,6 +179,9 @@ licenses:
222
179
  - MIT
223
180
  metadata:
224
181
  source_code_uri: https://github.com/digital-fabric/impression
182
+ documentation_uri: https://www.rubydoc.info/gems/impression
183
+ homepage_uri: https://github.com/digital-fabric/impression
184
+ changelog_uri: https://github.com/digital-fabric/impression/blob/master/CHANGELOG.md
225
185
  post_install_message:
226
186
  rdoc_options:
227
187
  - "--title"
@@ -1,239 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require 'kramdown'
4
- require 'rouge'
5
- require 'kramdown-parser-gfm'
6
- require 'yaml'
7
- require 'rb-inotify'
8
- require 'papercraft'
9
-
10
- require_relative './errors'
11
-
12
- module Impression
13
- class Pages
14
- module RequestMethods
15
- def serve_page(pages)
16
- pages.serve(self)
17
- end
18
- end
19
-
20
- def initialize(base_path, opts = {})
21
- @base_path = base_path
22
- @opts = opts
23
- @opts[:pages] = self
24
-
25
- load
26
-
27
- if opts[:auto_reload]
28
- start_automatic_reloader
29
- end
30
- end
31
-
32
- def start_automatic_reloader
33
- notifier = INotify::Notifier.new
34
- watched = {}
35
- @map.each_value do |entry|
36
- path = entry[:full_path]
37
- next if watched[path]
38
-
39
- notifier.watch(path, :modify, :delete_self) { |e| handle_changed_file(path) }
40
- watched[path] = true
41
- end
42
- notifier.watch(@base_path, :moved_to, :create) do |event|
43
- path = event.absolute_name
44
- if File.file?(path)
45
- notifier.watch(path, :modify, :delete_self) { |e| handle_changed_file(path) }
46
- end
47
- handle_changed_file(path)
48
- end
49
- @reloader = spin do
50
- notify_io = notifier.to_io
51
- loop do
52
- notify_io.wait_readable
53
- notifier.process
54
- end
55
- end
56
- end
57
-
58
- def handle_changed_file(full_path)
59
- p handle_changed_file: full_path
60
- if !File.file?(full_path)
61
- @map.reject! { |k, v| v[:full_path] == full_path }
62
- return
63
- end
64
-
65
- path = File.basename(full_path)
66
- page = Page.new(path, full_path, @opts)
67
- permalink = page.permalink
68
- @map[permalink] = { page: page, full_path: full_path }
69
- @map['/'] = @map[permalink] if permalink == '/index'
70
- end
71
-
72
- def load
73
- @map = {}
74
- Dir['**/*', base: @base_path].each do |path|
75
- next if path =~ /\/_.+/
76
-
77
- full_path = File.join(@base_path, path)
78
- next unless File.file?(full_path)
79
-
80
- page = Page.new(path, full_path, @opts)
81
- @map[page.permalink] = { page: page, full_path: full_path }
82
- end
83
- @map['/'] = @map['/index']
84
- end
85
- alias_method :reload, :load
86
-
87
- def prev_page(page)
88
- keys = @map.keys
89
- case idx = keys.index(page.permalink)
90
- when 0, nil
91
- nil
92
- else
93
- @map[keys[idx - 1]][:page]
94
- end
95
- end
96
-
97
- def next_page(page)
98
- keys = @map.keys
99
- case idx = keys.index(page.permalink)
100
- when keys.size - 1, nil
101
- nil
102
- else
103
- @map[keys[idx + 1]][:page]
104
- end
105
- end
106
-
107
- def load_file(path)
108
- content = IO.read(path)
109
- end
110
-
111
- def serve(req)
112
- entry = @map[req.route_relative_path]
113
- raise NotFoundError unless entry
114
-
115
- body = render_page(entry[:page])
116
- req.respond(body, 'Content-Type' => 'text/html')
117
- rescue NotFoundError => e
118
- req.respond('Not found.', ':status' => e.http_status)
119
- end
120
- alias_method :call, :serve
121
-
122
- def render_page(page)
123
- layout_proc(page.layout).().render(pages: self, page: page)
124
- end
125
-
126
- def layout_proc(layout)
127
- full_path = File.expand_path("../_layouts/#{layout}.rb", @base_path)
128
- instance_eval("->(&block) do; #{IO.read(full_path)}; end", full_path)
129
- end
130
-
131
- def select(selector)
132
- @map.inject([]) do |array, (permalink, entry)|
133
- array << entry[:page] if permalink =~ selector
134
- array
135
- end
136
- end
137
- end
138
-
139
- class Page
140
- attr_reader :attributes
141
-
142
- def initialize(path, full_path, opts = {})
143
- @path = path
144
- @full_path = full_path
145
- @opts = opts
146
- @kind = detect_page_kind(full_path)
147
- read_page
148
- end
149
-
150
- EXTNAME_REGEXP = /^\.(.+)$/.freeze
151
-
152
- def detect_page_kind(path)
153
- File.extname(path).match(EXTNAME_REGEXP)[1].to_sym
154
- end
155
-
156
- PAGE_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m.freeze
157
-
158
- def read_page
159
- data = IO.read(@full_path) || ''
160
- if data =~ PAGE_REGEXP
161
- front_matter = Regexp.last_match(1)
162
- @content_start_line = front_matter.lines.size + 2
163
- @attributes = YAML.load(front_matter)
164
- @content = Regexp.last_match.post_match
165
- else
166
- @attributes = {}
167
- @content_start_line = 1
168
- @content = data
169
- end
170
- end
171
-
172
- def permalink
173
- @permalink = @attributes[:permalink] || path_without_extension
174
- end
175
-
176
- def path_without_extension
177
- "/#{@path.delete_suffix(File.extname(@path))}"
178
- end
179
-
180
- def title
181
- @attributes['title'] || title_from_content
182
- end
183
-
184
- def prev_page
185
- @opts[:pages].prev_page(self)
186
- end
187
-
188
- def next_page
189
- @opts[:pages].next_page(self)
190
- end
191
-
192
- TITLE_REGEXP = /^#\s+([^\n]+)/.freeze
193
-
194
- def title_from_content
195
- (@content =~ TITLE_REGEXP) && Regexp.last_match(1)
196
- end
197
-
198
- def status
199
- @attributes['status'] || Qeweney::Status::OK
200
- end
201
-
202
- def layout
203
- layout = @attributes['layout'] || 'default'
204
- end
205
-
206
- def render
207
- case @kind
208
- when :md
209
- render_markdown
210
- when :rb
211
- render_papercraft
212
- else
213
- raise "Invalid page kind #{kind.inspect}"
214
- end
215
- end
216
-
217
- def render_markdown
218
- Kramdown::Document.new(@content, **kramdown_options).to_html
219
- end
220
-
221
- def kramdown_options
222
- {
223
- entity_output: :numeric,
224
- syntax_highlighter: :rouge,
225
- input: 'GFM',
226
- hard_wrap: false
227
- }
228
- end
229
-
230
- def render_papercraft
231
- proc = instance_eval("->(&block) do; #{@content}; end", @full_path, @content_start_line)
232
- proc.().render(page: self, pages: @opts[:pages])
233
- end
234
- end
235
- end
236
-
237
- class Qeweney::Request
238
- include Impression::Pages::RequestMethods
239
- end