railz_lite 0.2.1 → 0.2.6

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: d9913416758845461437f605307b2a10be934ed1da34652947f9a2dcbfdb1caa
4
- data.tar.gz: 33c8f9a302c65d3f4f55ebcd1682458de7a856d2c0c66c4fc6e1c614d64792e6
3
+ metadata.gz: f212021508124c75b30ec2d598c39939597f7263f8a08d8909efedc5d13220e7
4
+ data.tar.gz: 2b45fc4a2b46f7aa168a48d1fc0c222cbeca5007c1c1df7400bbd591363388a7
5
5
  SHA512:
6
- metadata.gz: 900a8e1808fdfc07b4c5638c1a7fb0cc3357c15fe9eaf8a563c8b56596716fc12ba038a75df0fe462ddd7f2bffc42c6367c6743e9184fe4d63c3be5e8cd384ec
7
- data.tar.gz: 56cdd5db6f1d0b008f1ad9b34e24047da258601bd57b8d76723bf1ccd8a76bbad486c1ec7df5503965d3d0f1b1d3e7fb8e7939974e71739bfbee4d94ca762144
6
+ metadata.gz: d9a20d00eeab48b8738ee9f136468f97081a2b14c1819c9473277374a169cc8dbe85a45ee4ed48bfcc4df24856791019cf994df791d062c4a339d5d0ea83bc03
7
+ data.tar.gz: 0646d6b6f01ac5c7998e9bf3c0431a34777cf22f7ac46e34756b2fc197832c9794949d2de2398c2ccbdaa5f2c8d59497a3dacaca62d9c2e5ace82fa1eae261bf
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ Gemfile.lock
@@ -14,7 +14,6 @@ module RailzLite
14
14
  def server
15
15
  file = File.join(Dir.pwd, 'config', 'server.rb')
16
16
  if File.exist?(file)
17
- DBConnection.start # load our db connection
18
17
  system('ruby', file)
19
18
  else
20
19
  raise "File not found at #{file}"
@@ -1,10 +1,14 @@
1
1
  require 'active_support'
2
2
  require 'active_support/core_ext'
3
3
  require 'erb'
4
+ require 'loofah'
4
5
  require_relative './session'
5
6
  require_relative './flash'
6
7
 
7
8
  module RailzLite
9
+ class LayoutRenderer # dummy class used to pass yield blocks into ERB method results https://hostiledeveloper.com/2015/05/28/working-with-templates-in-ruby-erb.html
10
+ end
11
+
8
12
  class ControllerBase
9
13
  attr_reader :req, :res, :params
10
14
 
@@ -46,10 +50,24 @@ module RailzLite
46
50
  # pass the rendered html to render_content
47
51
  def render(template_name)
48
52
  dir_path = Dir.pwd
49
- file_path = File.join(dir_path, 'views', "#{self.class.name.underscore.split('_controller').first}", "#{template_name.to_s}.html.erb")
50
- file = File.read(file_path)
51
- template = ERB.new(file).result(binding)
52
- render_content(template, 'text/html')
53
+
54
+ layout_path = File.join(dir_path, 'views', 'application', 'application.html.erb')
55
+ inner_file_path = File.join(dir_path, 'views', "#{self.class.name.underscore.split('_controller').first}", "#{template_name.to_s}.html.erb")
56
+
57
+ layout_template = File.read(layout_path)
58
+ inner_template = File.read(inner_file_path)
59
+
60
+ layout = ERB.new(layout_template)
61
+ inner = ERB.new(inner_template)
62
+
63
+ layout.def_method(LayoutRenderer, 'render') # dummy method used so that blocks can be passed to ERB result
64
+
65
+ result = LayoutRenderer.new.render do
66
+ inner_html = inner.result(binding)
67
+ Loofah.fragment(inner_html).scrub!(:prune).to_s # prevent non-safe html from being executed
68
+ end
69
+
70
+ render_content(result, 'text/html')
53
71
  end
54
72
 
55
73
  # method exposing a `Session` object
@@ -1,11 +1,11 @@
1
1
  require 'rack'
2
2
 
3
3
  class Static
4
- attr_reader :app, :file_server, :root
4
+ attr_reader :app, :file_server, :root_paths
5
5
 
6
6
  def initialize(app)
7
7
  @app = app
8
- @root = 'public'
8
+ @root_paths = ['public', 'assets']
9
9
  @file_server = FileServer.new
10
10
  end
11
11
 
@@ -23,7 +23,7 @@ class Static
23
23
  private
24
24
 
25
25
  def can_match?(path)
26
- path.index("/#{root}")
26
+ root_paths.any? { |root| path.index("/#{root}") }
27
27
  end
28
28
  end
29
29
 
@@ -32,7 +32,9 @@ class FileServer
32
32
  MIME_TYPES = {
33
33
  '.txt' => 'text/plain',
34
34
  '.jpg' => 'image/jpeg',
35
- '.zip' => 'application/zip'
35
+ '.zip' => 'application/zip',
36
+ '.css' => 'text/css',
37
+ '.js' => 'text/javascript'
36
38
  }
37
39
 
38
40
  def call(env)
@@ -26,8 +26,13 @@ module RailzLite
26
26
  template('server.rb', "#{project_name}/config/server.rb")
27
27
  end
28
28
 
29
- def add_welcome_view
29
+ def setup_views
30
30
  template('welcome_view.index.html.erb', "#{project_name}/views/welcome/index.html.erb")
31
+ template('application.html.erb', "#{project_name}/views/application/application.html.erb")
32
+ end
33
+
34
+ def add_assets
35
+ create_file("#{project_name}/assets/application.css")
31
36
  end
32
37
 
33
38
  def add_public
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>App Title</title>
5
+ <link rel="stylesheet" href="assets/application.css">
6
+ </head>
7
+ <body>
8
+ <%= yield %>
9
+ </body>
10
+ </html>
@@ -6,7 +6,7 @@
6
6
  ">
7
7
  <h1>Welcome To Railz Lite!</h1>
8
8
 
9
- <img src="../public/winter_fox_large.jpg" />
9
+ <img src="public/winter_fox_large.jpg" />
10
10
 
11
11
  <h3>For guidelines on how to build an app with this framework see <a href="https://github.com/bryanqb07/railz_lite">here</a>.</h3>
12
12
  </div>
@@ -29,7 +29,7 @@ class DBConnection
29
29
  end
30
30
 
31
31
  def self.instance
32
- reset if @db.nil?
32
+ start if @db.nil?
33
33
 
34
34
  @db
35
35
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RailzLite
4
- VERSION = "0.2.1"
4
+ VERSION = "0.2.6"
5
5
  end
data/railz_lite.gemspec CHANGED
@@ -29,11 +29,12 @@ Gem::Specification.new do |spec|
29
29
  spec.require_paths = ["lib"]
30
30
 
31
31
  # Uncomment to register a new dependency of your gem
32
- spec.add_dependency "rack"
33
- spec.add_dependency "activesupport"
34
- spec.add_dependency "puma"
35
- spec.add_dependency "sqlite3"
36
- spec.add_dependency "thor"
32
+ spec.add_dependency "rack", '~> 2.2.3'
33
+ spec.add_dependency "activesupport", '~> 6.1.4'
34
+ spec.add_dependency "puma", '~> 5.3.2'
35
+ spec.add_dependency "sqlite3", '~> 1.4.2'
36
+ spec.add_dependency "thor", '~> 1.1.0'
37
+ spec.add_dependency "loofah", '~> 2.10.0'
37
38
 
38
39
 
39
40
  spec.add_development_dependency "byebug"
metadata CHANGED
@@ -1,85 +1,99 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: railz_lite
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - bryan lynch
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-07-02 00:00:00.000000000 Z
11
+ date: 2021-07-03 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: 2.2.3
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: 2.2.3
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activesupport
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 6.1.4
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 6.1.4
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: puma
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: 5.3.2
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: 5.3.2
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: sqlite3
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: '0'
61
+ version: 1.4.2
62
62
  type: :runtime
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - "~>"
67
67
  - !ruby/object:Gem::Version
68
- version: '0'
68
+ version: 1.4.2
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: thor
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - "~>"
74
74
  - !ruby/object:Gem::Version
75
- version: '0'
75
+ version: 1.1.0
76
76
  type: :runtime
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - "~>"
81
81
  - !ruby/object:Gem::Version
82
- version: '0'
82
+ version: 1.1.0
83
+ - !ruby/object:Gem::Dependency
84
+ name: loofah
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 2.10.0
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 2.10.0
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: byebug
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -166,6 +180,7 @@ files:
166
180
  - lib/railz_lite/controllers/templates/rescue.html.erb
167
181
  - lib/railz_lite/generators/project.rb
168
182
  - lib/railz_lite/generators/project.rb~
183
+ - lib/railz_lite/generators/templates/application.html.erb
169
184
  - lib/railz_lite/generators/templates/application_controller.rb~
170
185
  - lib/railz_lite/generators/templates/server.rb
171
186
  - lib/railz_lite/generators/templates/welcome_view.index.html.erb