serduk 0.1.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: 719e028bf8fee5792bfaa54e0a8494dd931e22a8218087e6349a3d70bfc92923
4
+ data.tar.gz: 4b97530b2fdae4c73b097028f79be8eabbf32bce8639e89caa072dfdb5d83025
5
+ SHA512:
6
+ metadata.gz: 3128c46e47a3dda1915523fddf975f842ca0b5458c513e1e1f6303f8739f7a09dfc49d482173474bcbf2b74a22d5de2b52ec12868d0a3fc6d17460ed474d79f4
7
+ data.tar.gz: 8c382cc291c61791f74f003520e0fe4504a771362aeef70d8f2e648c91f8b6b99f75c412451e7b1176977542bacea2c9b4ff88310b009270ee6395d4e5d8213e
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.standard.yml ADDED
@@ -0,0 +1,3 @@
1
+ # For available configuration options, see:
2
+ # https://github.com/standardrb/standard
3
+ ruby_version: 3.0
data/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # Changelog
2
+
3
+ ## [0.1.0] - 2024-05-15
4
+
5
+ ### Added
6
+
7
+ - Created basic Web-framework.
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2024 Oleksandr Avoiants
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.
data/README.md ADDED
@@ -0,0 +1,88 @@
1
+ # Serduk (SErving Ruby Directory Universal Kit)
2
+
3
+ Simple Ruby Web Framework designed mainly for learning Web Development for everyone. Inspired by PHP. To make a new Web page just create an html file which supports ERB. E.g. for https:://yoursite.com/products.html create page products.html with any Ruby code.
4
+
5
+ ## Installation
6
+
7
+ Ruby programming language should be installed.
8
+
9
+ Install the gem by executing:
10
+
11
+ $ gem install serduk
12
+
13
+ ## Usage Examples
14
+
15
+ Create any HTML site that supports Ruby code in HTML/JSON pages using ERB:
16
+
17
+ ~~~html
18
+ <!DOCTYPE html>
19
+ <html lang="en">
20
+ <head>
21
+ <meta charset="UTF-8">
22
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
23
+ <title>Using Ruby Code - Example</title>
24
+ </head>
25
+ <body>
26
+ <h1>Server Time:</h1>
27
+
28
+ <%= Time.now %>
29
+
30
+ <p>Reload the page to get current time.</p>
31
+ </body>
32
+ </html>
33
+ ~~~
34
+
35
+ Loop through collection:
36
+
37
+ ~~~html
38
+ <!DOCTYPE html>
39
+ <html lang="en">
40
+ <head>
41
+ <meta charset="UTF-8">
42
+ <meta name="viewport" content="width=device-width, initial-scale=1.0">
43
+ <title>Loop through collection - Example</title>
44
+ </head>
45
+ <body>
46
+ <h1>Users</h1>
47
+
48
+ <% users = [{name: "Alice"}, {name: "Bob"}] %>
49
+
50
+ <% for user in users %>
51
+ <p>USER: <%= user[:name] %></p>
52
+ <% end %>
53
+ </body>
54
+ </html>
55
+ ~~~
56
+
57
+ ## Templates Rendering
58
+
59
+ Create files `templates/header.html`, `templates/footer.html` containing site header and footer HTML respectively. Reuse the code in any HTML page:
60
+
61
+ ~~~html
62
+ <%= render "templates/header", title: "About Us" %>
63
+
64
+ <h1>About Us</h1>
65
+ <p>Welcome to our bookstore! We are passionate about books and believe in the power of storytelling to inspire, educate, and entertain. Our mission is to provide a curated selection of quality books that cater to diverse interests and preferences.</p>
66
+ <p>At Bookstore, we strive to create a welcoming and inclusive environment where book lovers of all ages can explore new worlds, discover hidden gems, and connect with fellow enthusiasts. Whether you're a seasoned bibliophile or just beginning your reading journey, we're here to help you find your next great read.</p>
67
+ <p>Thank you for choosing Bookstore as your destination for literary adventures. We look forward to serving you and being a part of your reading adventures!</p>
68
+
69
+ <%= render "templates/footer" %>
70
+ ~~~
71
+
72
+ ## More Examples
73
+
74
+ See site example: https://github.com/webdeva2b/bookstore-ruby_pages-example-app
75
+
76
+ ## Development
77
+
78
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
79
+
80
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
81
+
82
+ ## Contributing
83
+
84
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shhavel/serduk.
85
+
86
+ ## License
87
+
88
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ require "standard/rake"
9
+
10
+ task default: %i[spec standard]
data/exe/serduk ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rackup"
4
+ require "serduk"
5
+
6
+ options = Rackup::Server::Options.new.parse!(ARGV)
7
+
8
+ Rackup::Server.start(options.merge(app: Serduk))
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Serduk
4
+ VERSION = "0.1.1"
5
+ end
data/lib/serduk.rb ADDED
@@ -0,0 +1,63 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "serduk/version"
4
+
5
+ module Serduk
6
+ class MissingTemplateError < StandardError; end
7
+ ALLOWED_EXTNAMES = Set.new(%w[.html .htm .css .ico .txt .jpg .jpeg .png .svg .webmanifest]).freeze
8
+ FORBIDDEN_PATH_FRAGMENTS = ["", ".", ".."].freeze
9
+ TEMPLATE_EXTNAMES = ["", ".html", ".erb", ".html.erb"].freeze
10
+
11
+ def self.call(env)
12
+ web_path_arr = env["PATH_INFO"].split("/").reject do |d|
13
+ FORBIDDEN_PATH_FRAGMENTS.include?(d)
14
+ end
15
+ os_path = File.join(Dir.getwd, *web_path_arr)
16
+ ext = File.extname(env["PATH_INFO"])
17
+ if ext.empty?
18
+ os_path = File.join(os_path, "index.html")
19
+ ext = ".html"
20
+ end
21
+ render_file(env, os_path, ext)
22
+ end
23
+
24
+ def self.render_file(env, filename, ext)
25
+ return render_404(env) unless ALLOWED_EXTNAMES.include?(ext) && File.file?(filename)
26
+ body = File.read(filename)
27
+ if ext == ".html" || ext == ".json"
28
+ bind = binding
29
+ bind.local_variable_set("env", env)
30
+ body = ERB.new(body).result(bind)
31
+ end
32
+ [200, headers(ext), [body]]
33
+ end
34
+
35
+ def self.render_404(env)
36
+ file404 = File.join(Dir.getwd, "404.html")
37
+ bind = binding
38
+ bind.local_variable_set("env", env)
39
+ body = File.file?(file404) ? ERB.new(File.read(file404)).result(bind) : "Page Not Found Error."
40
+ [404, {"content-type" => "text/html"}, [body]]
41
+ end
42
+
43
+ def self.headers(ext)
44
+ return {"content-type" => "text/html"} if ext == ".html"
45
+ return {"content-type" => "application/json"} if ext == ".json"
46
+ {}
47
+ end
48
+
49
+ def self.render(partial, **options)
50
+ partname = File.join(Dir.getwd, partial)
51
+ TEMPLATE_EXTNAMES.each do |ext|
52
+ filename = partname + ext
53
+ if File.file?(filename)
54
+ bind = binding
55
+ options.each do |key, value|
56
+ bind.local_variable_set(key, value)
57
+ end
58
+ return ERB.new(File.read(filename)).result(bind)
59
+ end
60
+ end
61
+ raise MissingTemplateError, "Template partial #{partial} doesn't exist."
62
+ end
63
+ end
data/sig/serduk.rbs ADDED
@@ -0,0 +1,4 @@
1
+ module RubyPages
2
+ VERSION: String
3
+ # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
+ end
metadata ADDED
@@ -0,0 +1,172 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: serduk
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Oleksandr Avoiants
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '3.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '3.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rackup
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.1'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.1'
41
+ - !ruby/object:Gem::Dependency
42
+ name: activerecord
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '7.1'
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '7.1'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pg
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.5'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.5'
69
+ - !ruby/object:Gem::Dependency
70
+ name: mysql2
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '0.5'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '0.5'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rspec
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.12.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 3.12.0
97
+ - !ruby/object:Gem::Dependency
98
+ name: rack-test
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 2.1.0
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 2.1.0
111
+ - !ruby/object:Gem::Dependency
112
+ name: pry
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: '0.5'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: '0.5'
125
+ description: Simple Ruby Web Framework designed mainly for learning Web Development
126
+ for everyone. Inspired by PHP. To make a new Web page just create an html file which
127
+ supports ERB. E.g. for https:://yoursite.com/products.html create page products.html
128
+ with any Ruby code.
129
+ email:
130
+ - shhavel@gmail.com
131
+ executables:
132
+ - serduk
133
+ extensions: []
134
+ extra_rdoc_files: []
135
+ files:
136
+ - ".rspec"
137
+ - ".standard.yml"
138
+ - CHANGELOG.md
139
+ - LICENSE.txt
140
+ - README.md
141
+ - Rakefile
142
+ - exe/serduk
143
+ - lib/serduk.rb
144
+ - lib/serduk/version.rb
145
+ - sig/serduk.rbs
146
+ homepage: https://github.com/webdeva2b/ruby_pages/tree/serduk
147
+ licenses:
148
+ - MIT
149
+ metadata:
150
+ homepage_uri: https://github.com/webdeva2b/ruby_pages/tree/serduk
151
+ source_code_uri: https://github.com/webdeva2b/ruby_pages/tree/serduk
152
+ changelog_uri: https://github.com/webdeva2b/ruby_pages/blob/serduk/CHANGELOG.md
153
+ post_install_message:
154
+ rdoc_options: []
155
+ require_paths:
156
+ - lib
157
+ required_ruby_version: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: 3.0.0
162
+ required_rubygems_version: !ruby/object:Gem::Requirement
163
+ requirements:
164
+ - - ">="
165
+ - !ruby/object:Gem::Version
166
+ version: '0'
167
+ requirements: []
168
+ rubygems_version: 3.5.6
169
+ signing_key:
170
+ specification_version: 4
171
+ summary: Simple Ruby Web Framework
172
+ test_files: []