ruby_pages 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: c93b578f7f2e6738ead128cfed9d56af2e10e8a77809db5915cd338c8cf1034c
4
+ data.tar.gz: fcf95bbd179b6a76c813c36079d8bc0f5bbefdb29d8854f0fcc318e9f84907fd
5
+ SHA512:
6
+ metadata.gz: c80d0c2160b9ff7fbf0f148d021caf1e67ab53ffbc1868f6523b908faa6c87570439d31d90be628bc24bd115ffdb7872bda1a39dba96f4768f08803297525a42
7
+ data.tar.gz: d19ac8ab8755a33948b9407f651b4a08a3bceed5e00ab5a2cf6075125d0bfb3689cd5560828e9a467a6917fafe5fd4835f2f211488b435c4b914271aa23dc00b
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,35 @@
1
+ # RubyPages
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
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/ruby_pages`. To experiment with that code, run `bin/console` for an interactive prompt.
6
+
7
+ ## Installation
8
+
9
+ TODO: Replace `UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG` with your gem name right after releasing it to RubyGems.org. Please do not do it earlier due to security reasons. Alternatively, replace this section with instructions to install your gem from git if you don't plan to release to RubyGems.org.
10
+
11
+ Install the gem and add to the application's Gemfile by executing:
12
+
13
+ $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
14
+
15
+ If bundler is not being used to manage dependencies, install the gem by executing:
16
+
17
+ $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Development
24
+
25
+ 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.
26
+
27
+ 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).
28
+
29
+ ## Contributing
30
+
31
+ Bug reports and pull requests are welcome on GitHub at https://github.com/shhavel/ruby_pages.
32
+
33
+ ## License
34
+
35
+ 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/ruby_pages ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "rackup"
4
+ require "ruby_pages"
5
+
6
+ options = Rackup::Server::Options.new.parse!(ARGV)
7
+
8
+ Rackup::Server.start(options.merge(app: RubyPages))
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubyPages
4
+ VERSION = "0.1.0"
5
+ end
data/lib/ruby_pages.rb ADDED
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "ruby_pages/version"
4
+
5
+ module RubyPages
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(os_path, ext)
22
+ end
23
+
24
+ def self.render_file(filename, ext)
25
+ return render_404 unless ALLOWED_EXTNAMES.include?(ext) && File.file?(filename)
26
+ body = File.read(filename)
27
+ if ext == ".html" || ext == ".json"
28
+ body = ERB.new(body).result(binding)
29
+ end
30
+ [200, headers(ext), [body]]
31
+ end
32
+
33
+ def self.render_404
34
+ file404 = File.join(Dir.getwd, "404.html")
35
+ body = File.file?(file404) ? File.read(file404) : "Page Not Found Error."
36
+ [404, {"content-type" => "text/html"}, [body]]
37
+ end
38
+
39
+ def self.headers(ext)
40
+ return {"content-type" => "text/html"} if ext == ".html"
41
+ return {"content-type" => "application/json"} if ext == ".json"
42
+ {}
43
+ end
44
+
45
+ def self.render(partial, **options)
46
+ partname = File.join(Dir.getwd, partial)
47
+ TEMPLATE_EXTNAMES.each do |ext|
48
+ filename = partname + ext
49
+ if File.file?(filename)
50
+ bind = binding
51
+ options.each do |key, value|
52
+ bind.local_variable_set(key, value)
53
+ end
54
+ return ERB.new(File.read(filename)).result(bind)
55
+ end
56
+ end
57
+ raise MissingTemplateError, "Template partial #{partial} doesn't exist."
58
+ end
59
+ end
@@ -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,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_pages
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Oleksandr Avoiants
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2024-05-15 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
+ description: Simple Ruby Web Framework designed mainly for learning Web Development
84
+ for everyone. Inspired by PHP. To make a new Web page just create an html file which
85
+ supports ERB. E.g. for https:://yoursite.com/products.html create page products.html
86
+ with any Ruby code.
87
+ email:
88
+ - shhavel@gmail.com
89
+ executables:
90
+ - ruby_pages
91
+ extensions: []
92
+ extra_rdoc_files: []
93
+ files:
94
+ - ".rspec"
95
+ - ".standard.yml"
96
+ - CHANGELOG.md
97
+ - LICENSE.txt
98
+ - README.md
99
+ - Rakefile
100
+ - exe/ruby_pages
101
+ - lib/ruby_pages.rb
102
+ - lib/ruby_pages/version.rb
103
+ - sig/ruby_pages.rbs
104
+ homepage: https://github.com/shhavel/ruby_pages
105
+ licenses:
106
+ - MIT
107
+ metadata:
108
+ homepage_uri: https://github.com/shhavel/ruby_pages
109
+ source_code_uri: https://github.com/shhavel/ruby_pages
110
+ changelog_uri: https://github.com/shhavel/ruby_pages/CHANGELOG.md
111
+ post_install_message:
112
+ rdoc_options: []
113
+ require_paths:
114
+ - lib
115
+ required_ruby_version: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: 3.0.0
120
+ required_rubygems_version: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ requirements: []
126
+ rubygems_version: 3.5.6
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Simple Ruby Web Framework
130
+ test_files: []