ruby_pages 0.1.0 → 0.1.1

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: c93b578f7f2e6738ead128cfed9d56af2e10e8a77809db5915cd338c8cf1034c
4
- data.tar.gz: fcf95bbd179b6a76c813c36079d8bc0f5bbefdb29d8854f0fcc318e9f84907fd
3
+ metadata.gz: 6ca1f5a963085b84c3371c193f8ad67b5100f637eff6e9f2a2d49316533ceb3f
4
+ data.tar.gz: b164e9b3fa4ac880abed822942d1de92a6cce7f78936a1b899dd0f307fc002bf
5
5
  SHA512:
6
- metadata.gz: c80d0c2160b9ff7fbf0f148d021caf1e67ab53ffbc1868f6523b908faa6c87570439d31d90be628bc24bd115ffdb7872bda1a39dba96f4768f08803297525a42
7
- data.tar.gz: d19ac8ab8755a33948b9407f651b4a08a3bceed5e00ab5a2cf6075125d0bfb3689cd5560828e9a467a6917fafe5fd4835f2f211488b435c4b914271aa23dc00b
6
+ metadata.gz: fdae921652a02135ffef2465871236020a8705995e80378885cd6a3cf03ee049a9512da3a2f146a48286daceb048dec012178ee1818eae8598b1237e920363a1
7
+ data.tar.gz: bbe72eafa6f9b284be02a5fe690bae68da9d3e6fc582f3b9d4e537f93155a53fd1afdbc460e783830528bec12e1216e046709a4b28755bc2b036394e6e1a4c85
data/README.md CHANGED
@@ -2,23 +2,76 @@
2
2
 
3
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
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
5
  ## Installation
8
6
 
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.
7
+ Ruby programming language should be installed.
8
+
9
+ Install the gem by executing:
10
+
11
+ $ gem install ruby_pages
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
10
58
 
11
- Install the gem and add to the application's Gemfile by executing:
59
+ Create files `templates/header.html`, `templates/footer.html` containing site header and footer HTML respectively. Reuse the code in any HTML page:
12
60
 
13
- $ bundle add UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
61
+ ~~~html
62
+ <%= render "templates/header", title: "About Us" %>
14
63
 
15
- If bundler is not being used to manage dependencies, install the gem by executing:
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>
16
68
 
17
- $ gem install UPDATE_WITH_YOUR_GEM_NAME_IMMEDIATELY_AFTER_RELEASE_TO_RUBYGEMS_ORG
69
+ <%= render "templates/footer" %>
70
+ ~~~
18
71
 
19
- ## Usage
72
+ ## More Examples
20
73
 
21
- TODO: Write usage instructions here
74
+ See site example: https://github.com/webdeva2b/bookstore-ruby_pages-example-app
22
75
 
23
76
  ## Development
24
77
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyPages
4
- VERSION = "0.1.0"
4
+ VERSION = "0.1.1"
5
5
  end
data/lib/ruby_pages.rb CHANGED
@@ -18,21 +18,25 @@ module RubyPages
18
18
  os_path = File.join(os_path, "index.html")
19
19
  ext = ".html"
20
20
  end
21
- render_file(os_path, ext)
21
+ render_file(env, os_path, ext)
22
22
  end
23
23
 
24
- def self.render_file(filename, ext)
25
- return render_404 unless ALLOWED_EXTNAMES.include?(ext) && File.file?(filename)
24
+ def self.render_file(env, filename, ext)
25
+ return render_404(env) unless ALLOWED_EXTNAMES.include?(ext) && File.file?(filename)
26
26
  body = File.read(filename)
27
27
  if ext == ".html" || ext == ".json"
28
- body = ERB.new(body).result(binding)
28
+ bind = binding
29
+ bind.local_variable_set("env", env)
30
+ body = ERB.new(body).result(bind)
29
31
  end
30
32
  [200, headers(ext), [body]]
31
33
  end
32
34
 
33
- def self.render_404
35
+ def self.render_404(env)
34
36
  file404 = File.join(Dir.getwd, "404.html")
35
- body = File.file?(file404) ? File.read(file404) : "Page Not Found Error."
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."
36
40
  [404, {"content-type" => "text/html"}, [body]]
37
41
  end
38
42
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_pages
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Oleksandr Avoiants
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-05-15 00:00:00.000000000 Z
11
+ date: 2024-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -80,6 +80,48 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
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'
83
125
  description: Simple Ruby Web Framework designed mainly for learning Web Development
84
126
  for everyone. Inspired by PHP. To make a new Web page just create an html file which
85
127
  supports ERB. E.g. for https:://yoursite.com/products.html create page products.html