railz_lite 0.2.1 → 0.2.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: d9913416758845461437f605307b2a10be934ed1da34652947f9a2dcbfdb1caa
4
- data.tar.gz: 33c8f9a302c65d3f4f55ebcd1682458de7a856d2c0c66c4fc6e1c614d64792e6
3
+ metadata.gz: c174580952b1c2956cf1d6bdbe7fbc0c7991a8b4401c98d63d3d3a9718ab4319
4
+ data.tar.gz: 3e32d2b2cc43e7ed406095e6934798e3c5fbafbe55f4965e3f08b732932d92ec
5
5
  SHA512:
6
- metadata.gz: 900a8e1808fdfc07b4c5638c1a7fb0cc3357c15fe9eaf8a563c8b56596716fc12ba038a75df0fe462ddd7f2bffc42c6367c6743e9184fe4d63c3be5e8cd384ec
7
- data.tar.gz: 56cdd5db6f1d0b008f1ad9b34e24047da258601bd57b8d76723bf1ccd8a76bbad486c1ec7df5503965d3d0f1b1d3e7fb8e7939974e71739bfbee4d94ca762144
6
+ metadata.gz: dca26645dca90b0a88e43ff6790083c7df11d1cff5b1b880d832156d1675e71f50e5310d2e01815b83b6f93c75f38a9c36b0b3e4ea21225e855d40b677647bfb
7
+ data.tar.gz: 6b682f976740cc0b9127bd7673fd520c7cbff38392aa54c3c7079bc5f1dc14274f452cefa3f6fdaf4388e317f73b9b97cc8b8f773c9e92499ba8e03ff0f5b93c
@@ -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}"
@@ -5,6 +5,9 @@ require_relative './session'
5
5
  require_relative './flash'
6
6
 
7
7
  module RailzLite
8
+ 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
9
+ end
10
+
8
11
  class ControllerBase
9
12
  attr_reader :req, :res, :params
10
13
 
@@ -46,10 +49,23 @@ module RailzLite
46
49
  # pass the rendered html to render_content
47
50
  def render(template_name)
48
51
  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')
52
+
53
+ layout_path = File.join(dir_path, 'views', 'application', 'application.html.erb')
54
+ inner_file_path = File.join(dir_path, 'views', "#{self.class.name.underscore.split('_controller').first}", "#{template_name.to_s}.html.erb")
55
+
56
+ layout_template = File.read(layout_path)
57
+ inner_template = File.read(inner_file_path)
58
+
59
+ layout = ERB.new(layout_template)
60
+ inner = ERB.new(inner_template)
61
+
62
+ layout.def_method(LayoutRenderer, 'render') # dummy method used so that blocks can be passed to ERB result
63
+
64
+ result = LayoutRenderer.new.render do
65
+ inner.result(binding)
66
+ end
67
+
68
+ render_content(result, 'text/html')
53
69
  end
54
70
 
55
71
  # method exposing a `Session` object
@@ -26,8 +26,10 @@ 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
+ create_file("#{project_name}/views/application/application.css")
31
33
  end
32
34
 
33
35
  def add_public
@@ -0,0 +1,10 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>App Title</title>
5
+ <link rel="stylesheet" href="application.css">
6
+ </head>
7
+ <body>
8
+ <%= yield %>
9
+ </body>
10
+ </html>
@@ -7,6 +7,7 @@ class DBConnection
7
7
  DB_FILE = File.join(ROOT_FOLDER, 'db', 'app.db')
8
8
 
9
9
  def self.start
10
+ `sqlite3 #{DB_FILE}`
10
11
  DBConnection.open(DB_FILE)
11
12
  end
12
13
 
@@ -29,7 +30,7 @@ class DBConnection
29
30
  end
30
31
 
31
32
  def self.instance
32
- reset if @db.nil?
33
+ start if @db.nil?
33
34
 
34
35
  @db
35
36
  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.2"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
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.2
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
@@ -166,6 +166,7 @@ files:
166
166
  - lib/railz_lite/controllers/templates/rescue.html.erb
167
167
  - lib/railz_lite/generators/project.rb
168
168
  - lib/railz_lite/generators/project.rb~
169
+ - lib/railz_lite/generators/templates/application.html.erb
169
170
  - lib/railz_lite/generators/templates/application_controller.rb~
170
171
  - lib/railz_lite/generators/templates/server.rb
171
172
  - lib/railz_lite/generators/templates/welcome_view.index.html.erb