impression 0.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: f5a7e55ef9ff6c795a485a4b1e50456949932d923425ad447ada836ef2e69b0c
4
+ data.tar.gz: 669f0781d30986542fb09aad0af058107a658281136ace716edfdefc18fefabb
5
+ SHA512:
6
+ metadata.gz: 1cdbfd6167b1e1717e5a3fda6089c84bb0ed7c6d810b1dac9376a1cd81a38a473c097ba6dd6ecbd07c61145b86b5e10f13c8be02ac69c14c556ba6991f87e4f4
7
+ data.tar.gz: cf2e071b60b5ed0aa0ab826d2721c55d15cabb7fa0f63e84d068f76eef9a39db68159d6a651ddf5371976c4703a72a910883e50becdd64ff365d4b955cb93192
data/.gitignore ADDED
@@ -0,0 +1,56 @@
1
+ *.gem
2
+ *.rbc
3
+ /.config
4
+ /coverage/
5
+ /InstalledFiles
6
+ /pkg/
7
+ /spec/reports/
8
+ /spec/examples.txt
9
+ /test/tmp/
10
+ /test/version_tmp/
11
+ /tmp/
12
+
13
+ # Used by dotenv library to load environment variables.
14
+ # .env
15
+
16
+ # Ignore Byebug command history file.
17
+ .byebug_history
18
+
19
+ ## Specific to RubyMotion:
20
+ .dat*
21
+ .repl_history
22
+ build/
23
+ *.bridgesupport
24
+ build-iPhoneOS/
25
+ build-iPhoneSimulator/
26
+
27
+ ## Specific to RubyMotion (use of CocoaPods):
28
+ #
29
+ # We recommend against adding the Pods directory to your .gitignore. However
30
+ # you should judge for yourself, the pros and cons are mentioned at:
31
+ # https://guides.cocoapods.org/using/using-cocoapods.html#should-i-check-the-pods-directory-into-source-control
32
+ #
33
+ # vendor/Pods/
34
+
35
+ ## Documentation cache and generated files:
36
+ /.yardoc/
37
+ /_yardoc/
38
+ /doc/
39
+ /rdoc/
40
+
41
+ ## Environment normalization:
42
+ /.bundle/
43
+ /vendor/bundle
44
+ /lib/bundler/man/
45
+
46
+ # for a library or gem, you might want to ignore these files since the code is
47
+ # intended to run in multiple environments; otherwise, check them in:
48
+ # Gemfile.lock
49
+ # .ruby-version
50
+ # .ruby-gemset
51
+
52
+ # unless supporting rvm < 1.11.0 or doing something fancy, ignore this:
53
+ .rvmrc
54
+
55
+ # Used by RuboCop. Remote config files pulled in from inherit_from directive.
56
+ # .rubocop-https?--*
data/CHANGELOG.md ADDED
File without changes
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,66 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ impression (0.1)
5
+ kramdown (~> 2.3.0)
6
+ kramdown-parser-gfm (~> 1.1.0)
7
+ polyphony (~> 0.51.0)
8
+ rouge (~> 3.26.0)
9
+ tipi (~> 0.37)
10
+
11
+ GEM
12
+ remote: https://rubygems.org/
13
+ specs:
14
+ ansi (1.5.0)
15
+ builder (3.2.4)
16
+ docile (1.3.5)
17
+ escape_utils (1.2.1)
18
+ http-2 (0.10.2)
19
+ http_parser.rb (0.6.0)
20
+ json (2.5.1)
21
+ kramdown (2.3.0)
22
+ rexml
23
+ kramdown-parser-gfm (1.1.0)
24
+ kramdown (~> 2.0)
25
+ minitest (5.11.3)
26
+ minitest-reporters (1.4.3)
27
+ ansi
28
+ builder
29
+ minitest (>= 5.0)
30
+ ruby-progressbar
31
+ msgpack (1.4.2)
32
+ polyphony (0.51.0)
33
+ qeweney (0.5)
34
+ escape_utils (~> 1.2.1)
35
+ rack (2.2.3)
36
+ rake (12.3.3)
37
+ rexml (3.2.4)
38
+ rouge (3.26.0)
39
+ ruby-progressbar (1.11.0)
40
+ simplecov (0.17.1)
41
+ docile (~> 1.1)
42
+ json (>= 1.8, < 3)
43
+ simplecov-html (~> 0.10.0)
44
+ simplecov-html (0.10.2)
45
+ tipi (0.37)
46
+ http-2 (~> 0.10.0)
47
+ http_parser.rb (~> 0.6.0)
48
+ msgpack (~> 1.4.2)
49
+ polyphony (~> 0.51.0)
50
+ qeweney (~> 0.5)
51
+ rack (>= 2.0.8, < 2.3.0)
52
+ websocket (~> 1.2.8)
53
+ websocket (1.2.9)
54
+
55
+ PLATFORMS
56
+ ruby
57
+
58
+ DEPENDENCIES
59
+ impression!
60
+ minitest (~> 5.11.3)
61
+ minitest-reporters (~> 1.4.2)
62
+ rake (~> 12.3.3)
63
+ simplecov (~> 0.17.1)
64
+
65
+ BUNDLED WITH
66
+ 2.1.4
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2021 Digital Fabric
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ # impression
2
+ A modern web framework for Ruby
data/TODO.md ADDED
File without changes
@@ -0,0 +1,24 @@
1
+ require 'bundler/setup'
2
+ require 'impression'
3
+ require 'tipi'
4
+
5
+ pages = Impression::Pages.new(File.join(__dir__, 'docs'))
6
+ app = pages.method(:serve).to_proc
7
+
8
+ opts = {
9
+ reuse_addr: true,
10
+ dont_linger: true
11
+ }
12
+
13
+ puts "pid: #{Process.pid}"
14
+ puts 'Listening on port 4411...'
15
+
16
+ Tipi.serve('0.0.0.0', 4411, opts) do |req|
17
+ app.call(req)
18
+ rescue Exception => e
19
+ p e
20
+ puts e.backtrace.join("\n")
21
+ status = e.respond_to?(:http_status) ? e.http_status : 500
22
+ req.respond(e.inspect, ':status' => status)
23
+ end
24
+ p 'done...'
@@ -0,0 +1,18 @@
1
+ ---
2
+ title: blah
3
+ ---
4
+ # Hello there
5
+
6
+ ## I'm an h2
7
+
8
+ ```ruby
9
+ "here's some code"
10
+
11
+ class A
12
+ def b
13
+ [:c, 42, /foo/]
14
+ end
15
+ end
16
+
17
+ p A.new.b
18
+ ```
@@ -0,0 +1,33 @@
1
+ require_relative './lib/impression/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'impression'
5
+ s.version = Impression::VERSION
6
+ s.licenses = ['MIT']
7
+ s.summary = 'Impression - a modern web framework for Ruby'
8
+ s.author = 'Sharon Rosner'
9
+ s.email = 'sharon@noteflakes.com'
10
+ s.files = `git ls-files`.split
11
+ s.homepage = 'http://github.com/digital-fabric/impression'
12
+ s.metadata = {
13
+ "source_code_uri" => "https://github.com/digital-fabric/impression"
14
+ }
15
+ s.rdoc_options = ["--title", "impression", "--main", "README.md"]
16
+ s.extra_rdoc_files = ["README.md"]
17
+ s.require_paths = ["lib"]
18
+ s.required_ruby_version = '>= 2.6'
19
+
20
+ # s.executables = ['impression']
21
+
22
+ s.add_runtime_dependency 'polyphony', '~>0.51.0'
23
+ s.add_runtime_dependency 'tipi', '~>0.37'
24
+ s.add_runtime_dependency 'kramdown', '~>2.3.0'
25
+ s.add_runtime_dependency 'rouge', '~>3.26.0'
26
+ s.add_runtime_dependency 'kramdown-parser-gfm', '~>1.1.0'
27
+
28
+
29
+ s.add_development_dependency 'rake', '~>12.3.3'
30
+ s.add_development_dependency 'minitest', '~>5.11.3'
31
+ s.add_development_dependency 'minitest-reporters', '~>1.4.2'
32
+ s.add_development_dependency 'simplecov', '~>0.17.1'
33
+ end
data/lib/impression.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative './impression/request_extensions'
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'qeweney/status'
4
+
5
+ module Impression
6
+ class BaseError < StandardError
7
+ def http_status
8
+ raise NotImplementedError
9
+ end
10
+ end
11
+
12
+ class NotFoundError < BaseError
13
+ def http_status
14
+ Qeweney::Status::NOT_FOUND
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'kramdown'
4
+ require 'rouge'
5
+ require 'kramdown-parser-gfm'
6
+ require 'yaml'
7
+
8
+ require_relative './errors'
9
+
10
+ module Impression
11
+ class Pages
12
+ module RequestMethods
13
+ def serve_page(pages)
14
+ pages.serve(self)
15
+ end
16
+ end
17
+
18
+ def initialize(base_path, opts = {})
19
+ @base_path = base_path
20
+ @opts = opts
21
+
22
+ load
23
+ end
24
+
25
+ def load
26
+ @map = {}
27
+ Dir['**/*', base: @base_path].each do |path|
28
+ next if path =~ /\/_.+/
29
+
30
+ full_path = File.join(@base_path, path)
31
+ next unless File.file?(full_path)
32
+
33
+ page = Page.new(path, full_path, @opts)
34
+ @map[page.relative_permalink] = page
35
+ end
36
+ @map['/'] = @map['/index']
37
+ end
38
+ alias_method :reload, :load
39
+
40
+ def load_file(path)
41
+ content = IO.read(path)
42
+ end
43
+
44
+ def serve(req)
45
+ page = @map[req.routing_path]
46
+ raise NotFoundError unless page
47
+
48
+ # return req.respond('Hello world')
49
+
50
+
51
+ req.respond(page.to_html, 'Content-Type' => 'text/html')
52
+ end
53
+
54
+ class Page
55
+ def initialize(path, full_path, opts = {})
56
+ @path = path
57
+ @full_path = full_path
58
+ @opts = opts
59
+ read_page
60
+ end
61
+
62
+ PAGE_REGEXP = /\A(---\s*\n.*?\n?)^((---|\.\.\.)\s*$\n?)/m.freeze
63
+
64
+ def read_page
65
+ data = IO.read(@full_path) || ''
66
+ if data =~ PAGE_REGEXP
67
+ front_matter = Regexp.last_match(1)
68
+ @attributes = YAML.load(front_matter)
69
+ @content = Regexp.last_match.post_match
70
+ else
71
+ @attributes = {}
72
+ @content = data
73
+ end
74
+ end
75
+
76
+ def relative_permalink
77
+ @relative_permalink = @attributes[:permalink] || path_without_extension
78
+ end
79
+
80
+ def path_without_extension
81
+ "/#{File.basename(@path, File.extname(@path))}"
82
+ end
83
+
84
+ def title
85
+ @attributes['title'] || title_from_content
86
+ end
87
+
88
+ TITLE_REGEXP = /^#\s+([^\n]+)/.freeze
89
+
90
+ def title_from_content
91
+ (@content =~ TITLE_REGEXP) && Regexp.last_match(1)
92
+ end
93
+
94
+ def status
95
+ @attributes['status'] || Qeweney::Status::OK
96
+ end
97
+
98
+ def to_html
99
+ @html ||= render_html
100
+ end
101
+
102
+ def kramdown_options
103
+ {
104
+ entity_output: :numeric,
105
+ syntax_highlighter: :rouge,
106
+ input: 'GFM'
107
+ }
108
+ end
109
+
110
+ def render_html
111
+ inner = Kramdown::Document.new(@content, **kramdown_options).to_html
112
+ "<!doctype html><html><body>#{inner}</body></html>"
113
+ end
114
+ end
115
+ end
116
+ end
117
+
118
+ class Qeweney::Request
119
+ include Impression::Pages::RequestMethods
120
+ end
@@ -0,0 +1,9 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'qeweney'
4
+
5
+ require_relative './pages'
6
+
7
+ class Qeweney::Request
8
+ include Impression::Pages::RequestMethods
9
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Impression
4
+ VERSION = '0.1'
5
+ end
metadata ADDED
@@ -0,0 +1,189 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: impression
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ platform: ruby
6
+ authors:
7
+ - Sharon Rosner
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-02-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: polyphony
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 0.51.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 0.51.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: tipi
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.37'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.37'
41
+ - !ruby/object:Gem::Dependency
42
+ name: kramdown
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: rouge
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 3.26.0
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 3.26.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: kramdown-parser-gfm
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: 1.1.0
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 1.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: rake
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 12.3.3
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 12.3.3
97
+ - !ruby/object:Gem::Dependency
98
+ name: minitest
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 5.11.3
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 5.11.3
111
+ - !ruby/object:Gem::Dependency
112
+ name: minitest-reporters
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 1.4.2
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 1.4.2
125
+ - !ruby/object:Gem::Dependency
126
+ name: simplecov
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - "~>"
130
+ - !ruby/object:Gem::Version
131
+ version: 0.17.1
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - "~>"
137
+ - !ruby/object:Gem::Version
138
+ version: 0.17.1
139
+ description:
140
+ email: sharon@noteflakes.com
141
+ executables: []
142
+ extensions: []
143
+ extra_rdoc_files:
144
+ - README.md
145
+ files:
146
+ - ".gitignore"
147
+ - CHANGELOG.md
148
+ - Gemfile
149
+ - Gemfile.lock
150
+ - LICENSE
151
+ - README.md
152
+ - TODO.md
153
+ - examples/markdown/app.rb
154
+ - examples/markdown/docs/index.md
155
+ - impression.gemspec
156
+ - lib/impression.rb
157
+ - lib/impression/errors.rb
158
+ - lib/impression/pages.rb
159
+ - lib/impression/request_extensions.rb
160
+ - lib/impression/version.rb
161
+ homepage: http://github.com/digital-fabric/impression
162
+ licenses:
163
+ - MIT
164
+ metadata:
165
+ source_code_uri: https://github.com/digital-fabric/impression
166
+ post_install_message:
167
+ rdoc_options:
168
+ - "--title"
169
+ - impression
170
+ - "--main"
171
+ - README.md
172
+ require_paths:
173
+ - lib
174
+ required_ruby_version: !ruby/object:Gem::Requirement
175
+ requirements:
176
+ - - ">="
177
+ - !ruby/object:Gem::Version
178
+ version: '2.6'
179
+ required_rubygems_version: !ruby/object:Gem::Requirement
180
+ requirements:
181
+ - - ">="
182
+ - !ruby/object:Gem::Version
183
+ version: '0'
184
+ requirements: []
185
+ rubygems_version: 3.1.4
186
+ signing_key:
187
+ specification_version: 4
188
+ summary: Impression - a modern web framework for Ruby
189
+ test_files: []