lively 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c7e42819f7548d59e893c416f38537446a4f64cdba0753cbca1ace1317f1a75f
4
+ data.tar.gz: ac926c52189a1d7ef707a1c2fb83e47aed149477de1021e0af5485a801063250
5
+ SHA512:
6
+ metadata.gz: 50f2c6841152c19b7a5198ec84f4ecd3a266a2f46ef02ff556b562535751608fce3e26d28a23acdc56ec1115671215fd0ed18f23f800cf37384c3a2b8615c6c4
7
+ data.tar.gz: f5bc7a16d4aab99165e6c739e12e5b94ceba62fff7f0859e262690cc89ab440ad5167df61f38bb0fba03dab86b0344eeb095c5524788c5e10ad87294c2263dab
data/lib/lively.rb ADDED
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
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
13
+ # all 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
21
+ # THE SOFTWARE.
22
+
23
+ require_relative 'lively/version'
24
+
25
+ require_relative 'lively/assets'
26
+ require_relative 'lively/application'
27
+
28
+ require_relative 'lively/environments/application'
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
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
13
+ # all 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
21
+ # THE SOFTWARE.
22
+
23
+ require 'live'
24
+ require 'async/websocket/adapters/http'
25
+
26
+ require_relative 'pages/index'
27
+
28
+ module Lively
29
+ class Application < Protocol::HTTP::Middleware
30
+ def initialize(delegate, resolver: self.class.resolver)
31
+ super(delegate)
32
+
33
+ @resolver = resolver
34
+ end
35
+
36
+ def live(connection)
37
+ Live::Page.new(@resolver).run(connection)
38
+ end
39
+
40
+ def title
41
+ self.class.name
42
+ end
43
+
44
+ def body
45
+ "Hello World"
46
+ end
47
+
48
+ def index
49
+ Pages::Index.new(title: self.title, body: self.body)
50
+ end
51
+
52
+ def call(request)
53
+ if request.path == '/live'
54
+ return Async::WebSocket::Adapters::HTTP.open(request, &self.method(:live)) || Protocol::HTTP::Response[400]
55
+ else
56
+ return Protocol::HTTP::Response[200, [], [self.index.call]]
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,83 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
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
13
+ # all 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
21
+ # THE SOFTWARE.
22
+
23
+ module Lively
24
+ class Assets < Protocol::HTTP::Middleware
25
+ DEFAULT_CACHE_CONTROL = 'public, max-age=3600'
26
+
27
+ DEFAULT_CONTENT_TYPES = {
28
+ ".html" => "text/html",
29
+ ".css" => "text/css",
30
+ ".js" => "application/javascript",
31
+ ".png" => "image/png",
32
+ ".jpeg" => "image/jpeg",
33
+ ".gif" => "image/gif",
34
+ }
35
+
36
+ def initialize(delegate, root: Dir.pwd, content_types: DEFAULT_CONTENT_TYPES, cache_control: DEFAULT_CACHE_CONTROL)
37
+ super(delegate)
38
+
39
+ @root = root
40
+
41
+ @content_types = content_types
42
+ @cache_control = cache_control
43
+ end
44
+
45
+ def freeze
46
+ return self if frozen?
47
+
48
+ @root.freeze
49
+ @content_types.freeze
50
+ @cache_control.freeze
51
+
52
+ super
53
+ end
54
+
55
+ def response_for(path, content_type)
56
+ headers = [
57
+ ['content-type', content_type],
58
+ ['cache-control', @cache_control],
59
+ ]
60
+
61
+ return Protocol::HTTP::Response[200, headers, Protocol::HTTP::Body::File.open(path)]
62
+ end
63
+
64
+ def expand_path(path)
65
+ File.realpath(File.join(@root, path))
66
+ rescue Errno::ENOENT
67
+ nil
68
+ end
69
+
70
+ def call(request)
71
+ if path = expand_path(request.path)
72
+ extension = File.extname(path)
73
+ content_type = @content_types[extension]
74
+
75
+ if path.start_with?(@root) && File.exist?(path) && content_type
76
+ return response_for(path, content_type)
77
+ end
78
+ end
79
+
80
+ super
81
+ end
82
+ end
83
+ end
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ # Copyright, 2021, by Samuel G. D. Williams. <http://www.codeotaku.com>
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
13
+ # all 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
21
+ # THE SOFTWARE.
22
+
23
+ module Lively
24
+ module Environments
25
+ module Application
26
+ def self.load(configuration)
27
+ configuration.load(:application)
28
+
29
+ configuration.environment(:lively, :application) do
30
+ # The middleware stack for the application.
31
+ # @attribute [Protocol::HTTP::Middleware]
32
+ middleware do
33
+ ::Protocol::HTTP::Middleware.build do |builder|
34
+ builder.use Assets, root: File.expand_path('../../../public', __dir__)
35
+ builder.use ::Application
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,23 @@
1
+
2
+ require 'trenni/template'
3
+
4
+ module Lively
5
+ module Pages
6
+ class Index
7
+ def initialize(title: "Lively", body: "Hello World")
8
+ @title = title
9
+ @body = body
10
+
11
+ path = File.expand_path("index.trenni", __dir__)
12
+ @template = Trenni::Template.load_file(path)
13
+ end
14
+
15
+ attr :title
16
+ attr :body
17
+
18
+ def call
19
+ @template.to_string(self)
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,19 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>#{self.title}</title>
5
+
6
+ <meta charset="UTF-8" />
7
+ <meta name="viewport" content="width=device-width, initial-scale=1" />
8
+
9
+ <link rel="icon" type="image/png" href="/_static/icon.png" />
10
+ <link rel="stylesheet" href="/_static/site.css" type="text/css" media="screen" />
11
+
12
+ <script src="/_components/morphdom/morphdom-umd.js"></script>
13
+ <script src="/_components/@socketry/live/live.js"></script>
14
+ </head>
15
+
16
+ <body>
17
+ #{self.body&.to_html || "No body specified!"}
18
+ </body>
19
+ </html>
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Lively
4
+ VERSION = "0.1.0"
5
+ end
metadata ADDED
@@ -0,0 +1,147 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: lively
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Samuel Williams
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2021-06-07 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: async-io
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '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'
27
+ - !ruby/object:Gem::Dependency
28
+ name: falcon
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: live
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: async-rspec
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.1'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.1'
69
+ - !ruby/object:Gem::Dependency
70
+ name: bundler
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: covered
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: '0.10'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: '0.10'
97
+ - !ruby/object:Gem::Dependency
98
+ name: rspec
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: '3.6'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: '3.6'
111
+ description:
112
+ email:
113
+ executables: []
114
+ extensions: []
115
+ extra_rdoc_files: []
116
+ files:
117
+ - lib/lively.rb
118
+ - lib/lively/application.rb
119
+ - lib/lively/assets.rb
120
+ - lib/lively/environments/application.rb
121
+ - lib/lively/pages/index.rb
122
+ - lib/lively/pages/index.trenni
123
+ - lib/lively/version.rb
124
+ homepage: https://github.com/socketry/lively
125
+ licenses:
126
+ - MIT
127
+ metadata: {}
128
+ post_install_message:
129
+ rdoc_options: []
130
+ require_paths:
131
+ - lib
132
+ required_ruby_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: 2.5.0
137
+ required_rubygems_version: !ruby/object:Gem::Requirement
138
+ requirements:
139
+ - - ">="
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ requirements: []
143
+ rubygems_version: 3.2.15
144
+ signing_key:
145
+ specification_version: 4
146
+ summary: A simple client-server SPA framework.
147
+ test_files: []