uni_rails 0.3.0 → 0.4.0

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: 3dbb41ea67dff2755cb5b77eae07f174a95bf99de2cf03a084739213c99033c9
4
- data.tar.gz: 5c9414944b4616651a429657025c58444f330ceea500f164a92a8d7afcefc824
3
+ metadata.gz: c4f9cd3df989797cabd98e67117c2767bf2aa19d8d586b86e62e8db1bc5962b4
4
+ data.tar.gz: 77c6a558483c47a3f08f8acbc1139290a90e2313f9f39cb48a17efb6996542d3
5
5
  SHA512:
6
- metadata.gz: 980ece2224b2c31320c749eb07676912f27bf5285d6dcefcacae4196f15061140185cb8b51a565d4605db0fd95a669ec543b1750fcdeb024fab4cc7d5a61d93a
7
- data.tar.gz: 49e8aa1ff7ec06d23cfa5a07d8d9546e036fe6255c71f6766faa42416631d0fdaf9d572333ebd066f6265e693f731586f77e19f3858f929f351cd82f28c4ff99
6
+ metadata.gz: c10ef57227cf6742fed28dd95c35d221dc3307a126244da83b34c7dc7fdd7b2d022ef63a92f607a873e276538e8bb665a863b3828e85d95f64647eb395f7394d
7
+ data.tar.gz: 2d7db16654876db5b7f28fd10d0ca5019a1070f8e90c2e6167f96e242d8b7c9dc535194a3d77635f1fa77b405f8dafb3f5860daf140265f6956c1cc14970f565
data/README.md CHANGED
@@ -8,12 +8,13 @@ Check out our [examples](/examples) to understand how the library creates Rails
8
8
 
9
9
  ## Installation & Usage
10
10
 
11
- See some examples of how the UniRails library can be used
11
+ See some examples of how the UniRails library can be used. Running an example is a easy as `ruby filename.rb`
12
12
 
13
13
  - [Hello world](/examples/hello-world.rb)
14
14
  - [Todos app (JSON API)](/examples/todos-api.rb)
15
15
  - [Todos app (Rails scaffold)](/examples/todos-scaffold.rb) based off `bin/rails g scaffold todo name completed_at:datetime`
16
16
  - [Todos app (Hotwire)](/examples/todos-hotwire.rb) based off online article: [turbo-rails-101-todo-list](https://www.colby.so/posts/turbo-rails-101-todo-list) by David Colby
17
+ - [App using StimulusJS](/examples/stimulus-app.rb)
17
18
  - [App using Puma server](/examples/server-puma-app.rb)
18
19
  - [App using Falcon server](/examples/server-falcon-app.rb)
19
20
 
@@ -0,0 +1,88 @@
1
+ ENV["SECRET_KEY_BASE"] = "1212312313"
2
+ ENV["DATABASE_URL"] = "sqlite3:///#{__dir__}/database.sqlite"
3
+
4
+ require "bundler/inline"
5
+
6
+ gemfile do
7
+ source "https://www.rubygems.org"
8
+ gem "uni_rails"
9
+ gem "sqlite3", "~> 1.7"
10
+ gem "byebug"
11
+ end
12
+
13
+ require "uni_rails"
14
+ require "sqlite3"
15
+ require "byebug"
16
+
17
+ # ==== ROUTES ====
18
+ UniRails::App.routes.append do
19
+ root "resource_names#new"
20
+ resources :resource_names
21
+ end
22
+
23
+ # ==== DB SCHEMA ====
24
+ ActiveRecord::Base.establish_connection
25
+ ActiveRecord::Schema.define do
26
+ create_table :resources, force: :cascade do |t|
27
+ t.string :title
28
+ end
29
+ end
30
+
31
+ # ==== MODELS ====
32
+ class Resource < ActiveRecord::Base
33
+ end
34
+
35
+ # ==== SEEDS ====
36
+ # Create your existing records here
37
+
38
+ # ==== CONTROLLERS ====
39
+ class ResourceNamesController < ActionController::Base
40
+ layout 'application'
41
+
42
+ def new
43
+ end
44
+
45
+ def create
46
+ end
47
+ end
48
+
49
+ # ==== IMPORT MAPS ====
50
+ UniRails.import_maps(
51
+ 'stimulus' => 'https://unpkg.com/@hotwired/stimulus/dist/stimulus.js'
52
+ )
53
+
54
+
55
+ # ==== JAVASCRTIP ====
56
+ UniRails.javascript <<~JAVASCRIPT
57
+ import { Application, Controller } from "stimulus"
58
+ window.Stimulus = Application.start()
59
+
60
+ Stimulus.register("hello", class extends Controller {
61
+ connect() {
62
+ console.log("hello world")
63
+ }
64
+ })
65
+
66
+ JAVASCRIPT
67
+
68
+ # ==== CSS ====
69
+ UniRails.css <<~CSS
70
+ html { background-color:#EEE; }
71
+ body { width:500px; height:700px; margin:auto;
72
+ background-color:white; padding:1rem;
73
+ }
74
+ form {
75
+ label { display: block; }
76
+ input[type="submit"] { display: block; margin-top:1rem; }
77
+ .field_with_errors { color:red; display:inline; }
78
+ }
79
+ CSS
80
+
81
+ # ==== VIEWS ====
82
+ UniRails.register_view "resource_names/new.html.erb", <<~HTML
83
+ HTML
84
+
85
+ UniRails.register_view "resource_names/show.html.erb", <<~HTML
86
+ HTML
87
+
88
+ UniRails.run(Port: 3000)
@@ -1,5 +1,3 @@
1
- # Run the application
2
- # $ ruby hello-world.rb
3
1
 
4
2
  ENV['SECRET_KEY_BASE'] = 'my_secret_key_base'
5
3
 
@@ -1,5 +1,3 @@
1
- # Run the application
2
- # $ ruby server-falcon-app.rb
3
1
 
4
2
  ENV['SECRET_KEY_BASE'] = 'my_secret_key_base'
5
3
 
@@ -1,5 +1,3 @@
1
- # Run the application
2
- # $ ruby server-puma-app.rb
3
1
 
4
2
  ENV['SECRET_KEY_BASE'] = 'my_secret_key_base'
5
3
 
@@ -0,0 +1,41 @@
1
+
2
+ ENV['SECRET_KEY_BASE'] = 'my_secret_key_base'
3
+
4
+ require "bundler/inline"
5
+
6
+ gemfile(true) do
7
+ source "https://rubygems.org"
8
+ gem 'uni_rails'
9
+ end
10
+
11
+ require 'uni_rails'
12
+
13
+ UniRails::App.routes.append do
14
+ root 'pages#index'
15
+ end
16
+
17
+ UniRails.import_maps(
18
+ 'stimulus' => 'https://unpkg.com/@hotwired/stimulus/dist/stimulus.js'
19
+ )
20
+
21
+ UniRails.javascript <<~JAVASCRIPT
22
+ import { Application, Controller } from "stimulus"
23
+ window.Stimulus = Application.start()
24
+
25
+ Stimulus.register("hello", class extends Controller {
26
+ connect() {
27
+ console.log("hello world")
28
+ }
29
+ })
30
+ JAVASCRIPT
31
+
32
+ class PagesController < ActionController::Base
33
+ layout 'application'
34
+ def index;end
35
+ end
36
+
37
+ UniRails.register_view "pages/index.html.erb", <<~HTML
38
+ <div data-controller="hello">Check out the dev console to see "hello world"</div>
39
+ HTML
40
+
41
+ UniRails.run(Port: 3000)
@@ -1,5 +1,3 @@
1
- # Run the application
2
- # $ ruby todos-api.rb
3
1
 
4
2
  ENV['SECRET_KEY_BASE'] = 'my_secret_key_base'
5
3
  ENV['DATABASE_URL'] = "sqlite3:///#{Dir.pwd}/todos-api.sqlite"
@@ -1,6 +1,4 @@
1
1
  # Based on the Hotwire tutorial: https://www.colby.so/posts/turbo-rails-101-todo-list
2
- # Run the application
3
- # $ ruby todos-hotwire.rb
4
2
 
5
3
  ENV['SECRET_KEY_BASE'] = 'my_secret_key_base'
6
4
  ENV['DATABASE_URL'] = "sqlite3:///#{Dir.pwd}/todos-hotwire.sqlite"
@@ -1,5 +1,3 @@
1
- # Run the application
2
- # $ ruby todos-scaffold.rb
3
1
 
4
2
  ENV['SECRET_KEY_BASE'] = 'my_secret_key_base'
5
3
  ENV['DATABASE_URL'] = "sqlite3:///#{Dir.pwd}/todos-scaffold.sqlite"
data/exe/unirails ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ # require "byebug"
4
+ # byebug
5
+
6
+ assets_path = File.expand_path('../assets', __dir__)
7
+
8
+ options = {}
9
+ case ARGV[0]
10
+ when "new"
11
+ filename = ARGV[1]
12
+ File.open(filename, 'wb+') do |f|
13
+ f.write File.read File.join(assets_path, 'templates', 'default.txt')
14
+ end
15
+ else
16
+ puts "unknown command"
17
+ puts "Usage: unirails new <filename>"
18
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UniRails
4
- VERSION = "0.3.0"
4
+ VERSION = "0.4.0"
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: uni_rails
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexandre Barret
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2024-04-19 00:00:00.000000000 Z
11
+ date: 2024-07-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -55,7 +55,8 @@ dependencies:
55
55
  description:
56
56
  email:
57
57
  - barret.alx@gmail.com
58
- executables: []
58
+ executables:
59
+ - unirails
59
60
  extensions: []
60
61
  extra_rdoc_files: []
61
62
  files:
@@ -63,12 +64,15 @@ files:
63
64
  - LICENSE.txt
64
65
  - README.md
65
66
  - Rakefile
67
+ - assets/templates/default.txt
66
68
  - examples/hello-world.rb
67
69
  - examples/server-falcon-app.rb
68
70
  - examples/server-puma-app.rb
71
+ - examples/stimulus-app.rb
69
72
  - examples/todos-api.rb
70
73
  - examples/todos-hotwire.rb
71
74
  - examples/todos-scaffold.rb
75
+ - exe/unirails
72
76
  - lib/uni_rails.rb
73
77
  - lib/uni_rails/app.rb
74
78
  - lib/uni_rails/app/css.rb