birdel 0.3.2 → 1.0.0

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: faab7b02dd01e572eaae3a25c2033282844cfe425546876c02ac6ba77905b522
4
- data.tar.gz: 54d4574fdcf44058042882d143db6b9cdd8630da9ce7c99d6676642b43805c2c
3
+ metadata.gz: 2c69242d504f173a3f2205c233f4c14985464d2067ab94ec8ac6bfa3916c98d8
4
+ data.tar.gz: '085ebfa1d118f7d9a17918bec92ee3c53c4bf236cc23a1ac278f624d2ce0d905'
5
5
  SHA512:
6
- metadata.gz: bd4b50c56c31c5573021c7003b22fa765798742259d170d69072ae1d2353796d093efc3616810c18a6084b96d18a68e82603df4468c3ff7edcf63766d29da48c
7
- data.tar.gz: 5c42e187572d125b2c2044f9f7fc41f43b53bc60ce8920806ef14be76fa9c651c7cb153d466941c11e9d21898f6508f6e8de5f1cb05ad10b821ee4902e78e186
6
+ metadata.gz: fb3ae839ec2fea84c5dd02bf38ab8fba11b4c968bd3336f1a5720ba573c34d4525546330b0bf6c898848880d9abb3b85a0d4b8e7ec38d5b659c2c5afd69da60a
7
+ data.tar.gz: 697841acce5a77178a9b4314a4e9ba6819849b772a65b22b5b904d4b424191a2b9808f986001197fcf18f1aed3f29d4f6ba892c80722efe294391167540f9eaf
data/Gemfile CHANGED
@@ -13,4 +13,6 @@ gem "rubocop", "~> 1.21"
13
13
 
14
14
  gem 'activesupport', '~> 7.0', '>= 7.0.4.3'
15
15
 
16
- gem 'colored', '~> 1.2'
16
+ gem 'colored', '~> 1.2'
17
+
18
+ gem 'thor', '~> 1.2', '>= 1.2.1'
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- birdel (0.2.16)
4
+ birdel (0.3.3)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -52,6 +52,7 @@ GEM
52
52
  rubocop-ast (1.27.0)
53
53
  parser (>= 3.2.1.0)
54
54
  ruby-progressbar (1.13.0)
55
+ thor (1.2.1)
55
56
  tzinfo (2.0.6)
56
57
  concurrent-ruby (~> 1.0)
57
58
  unicode-display_width (2.4.2)
@@ -66,6 +67,7 @@ DEPENDENCIES
66
67
  rake (~> 13.0)
67
68
  rspec (~> 3.0)
68
69
  rubocop (~> 1.21)
70
+ thor (~> 1.2, >= 1.2.1)
69
71
 
70
72
  BUNDLED WITH
71
73
  2.4.6
data/README.md CHANGED
@@ -1,146 +1,208 @@
1
- # Birdel - make rails great again 🐦
1
+ # Birdel - microframework for rails
2
+ The new coding way to server<->client speaking and assets management
3
+ ## 🛣️ Rona
4
+ This module proces JSON request and send inputs to actor method. Inside actor method you can write your custom code and response some output values. If request has required_component field - Rona module will authomatically render that component by passing outputs values to this component.
5
+
6
+ ### Rona usage example
7
+
8
+ ```js
9
+ // Birdel.js request
10
+ window.Birdel.send({
11
+ "actor": "ui__sunny_squirrel_actor",
12
+ "method": "get_article",
13
+ "required_component": "home--article-component",
14
+ "inputs": {
15
+ "articleId": 69
16
+ },
17
+ "callback": {
18
+ "component": "home--articles-component",
19
+ "actor": "articles-component-actor",
20
+ "method": "renderArticle",
21
+ "resource_id": false
22
+ }
23
+ });
24
+
25
+ //Response example
26
+ {
27
+ "ok": true,
28
+ "message": "Rendered article",
29
+ "data": {
30
+ "actor": "ui__sunny_squirrel_actor",
31
+ "method": "get_article",
32
+ "outputs": {
33
+ "article": {id:...}
34
+ },
35
+ "html": "<div>My Article component html</div>",
36
+ },
37
+ "callback": {
38
+ "component": "home--articles-component",
39
+ "actor": "articles-component-actor",
40
+ "method": "renderArticle",
41
+ "resource_id": false
42
+ }
43
+ }
44
+ ```
2
45
 
3
- Use actors as never before
46
+ ```js
47
+ // Birdel.js Direct request
48
+ window.Birdel.sendDirect({
49
+ "required_component": "home--confirm-modal-component",
50
+ "inputs": {
51
+ "confirmMessage": "Are you sure?"
52
+ },
53
+ "callback": {
54
+ "component": "home--modals-component",
55
+ "actor": "modals-component-actor",
56
+ "method": "appendModal",
57
+ "resource_id": false
58
+ }
59
+ });
60
+
61
+ //Response example
62
+ {
63
+ "ok": true,
64
+ "message": "Actor Direct",
65
+ "data": {
66
+ "outputs": {
67
+ "confirmMessage": "Are you sure?"
68
+ },
69
+ "html": "<div>My confirmation modal component html</div>",
70
+ },
71
+ "callback": {
72
+ "component": "home--articles-component",
73
+ "actor": "articles-component-actor",
74
+ "method": "renderArticle",
75
+ "resource_id": false
76
+ }
77
+ }
78
+ ```
4
79
 
5
- ## 🛣️ Rona - resolve request/respond
6
80
 
7
- Processing birdel.js actors requests based on request specifications. And response based on response specification
81
+ ```ruby
82
+ # Actor processor
83
+ class SunnySquirrelActor::SunnySquirrelActor
84
+ def get_article(inputs, current_user)
85
+ article_id = inputs.fetch("articleId")
86
+ article = Article.find_by(id: cupboard_id)
87
+ return {ok: false, message: "Article not found", outputs: {}} unless article
88
+ return {ok: true, message: "Article", outputs: {article: article}}
89
+ end
90
+ end
91
+ ```
8
92
 
9
- ## 🔄 Cif - Chain of Responsibility pattern
93
+ ```ruby
94
+ #Your main channel for current entry page
95
+ class HomeChannel < ApplicationCable::Channel
96
+ state_attr_accessor :first_stream
97
+ include Birdel::Rona
98
+
99
+ def subscribed
100
+ self.first_stream = "#{params[:channel]}_#{params[:id]}"
101
+ stream_from self.first_stream
102
+ end
103
+ end
104
+ ```
10
105
 
11
- Each actor should be sure, that previews actor successfully finished his job.
106
+ ## Blah Blah Blah
12
107
 
13
- ## 🧩 Components generator
108
+ - [ ] Cif - Chain of Responsibility pattern
109
+ - [x] Components generator
110
+ - [ ] Actors generator
111
+ - [ ] Actors specifications
112
+ - [x] Synth - rewrite CSS ans JS indexes
113
+ - [x] Map - generate entry page
14
114
 
15
- Birdel can generate actors (or components same to ViewComponent generator)
115
+ ## 📝 Map
16
116
 
17
- ```
18
- # Nested namespace example
19
- $ birdel act Ui::AngryCatActor
20
- ```
117
+ Entry pages indexes generator module
21
118
 
22
- ```
23
- app/
24
- ├─ bactors/
25
- ├─── ui/
26
- ├───── angry_cat_actor/
27
- ├─────── angry_cat_actor.rb
28
- ├─────── angry_cat_actor_specification.rb
29
- ```
119
+ ```bash
120
+ $ birdel map Ui::Bentries::Home
121
+ # + app/assets/stylesheets/ui/bentries/home/components.css.json
122
+ # + app/assets/stylesheets/ui/bentries/home/precomponents.css.json
123
+ # + app/assets/stylesheets/ui/bentries/home/components.css
124
+ # + app/assets/stylesheets/ui/bentries/home/precomponents.css
125
+ # + app/assets/stylesheets/ui/bentries/home/index.css
30
126
 
31
- ```
32
- $ birdel com Ui::TopBarComponent
33
- ```
127
+ # + app/javascript/ui/bentries/home/components.js.json
128
+ # + app/javascript/ui/bentries/home/components.js
129
+ # + app/javascript/ui/bentries/home/index.js
34
130
 
35
- ```
36
- app/
37
- ├─ components/
38
- │ ├─ ui/
39
- │ │ ├─ top_bar_component/
40
- │ │ │ ├─ top_bar_component.rb
41
- │ │ │ ├─ top_bar_component.js
42
- │ │ │ ├─ top_bar_component.css
43
- │ │ │ ├─ top_bar_component_controller.js
44
- │ │ │ └─ top_bar_component_actor.js
131
+ # + app/viewslayouts/ui/bentries/home/index.html.erb
45
132
  ```
46
133
 
47
- ## 📈 Synth - Building indexes
48
-
49
- You should store your entries same to this:
134
+ ### Visualized files structure
50
135
  ```
136
+ # Css structure
51
137
  app/
52
138
  ├─ assets/
53
139
  │ ├─ stylesheets/
140
+ │ │ ├─ ui/
141
+ │ │ │ ├─ bentries/
142
+ │ │ │ │ ├─ some_page/
143
+ │ │ │ │ │ ├─ index.css
144
+ │ │ │ │ │ ├─ components.css
145
+ │ │ │ │ │ ├─ precomponents.css.json
146
+ │ │ │ │ │ └─ components.css.json
147
+
148
+ # Javascript structure
149
+ ├─ javascript/
150
+ │ ├─ ui/
54
151
  │ │ ├─ bentries/
55
- │ │ │ ├─ home/
56
- │ │ │ │ ├─ index.css
57
- │ │ │ │ ├─ components.css
58
- │ │ │ │ ├─ precomponents.json
59
- │ │ │ │ └─ components.json
60
152
  │ │ │ ├─ some_page/
61
- │ │ │ │ ├─ index.css
62
- │ │ │ │ ├─ components.css
63
- │ │ │ │ ├─ precomponents.json
64
- │ │ │ │ └─ components.json
153
+ │ │ │ │ ├─ index.js
154
+ │ │ │ │ ├─ components.js
155
+ │ │ │ │ └─ components.js.json
65
156
 
66
- # Feel free to put bentries/ folder inside some nested folder in stylesheets/
67
- ```
157
+ # Actors structure
158
+ app/
159
+ ├─ ui/
160
+ │ ├─ bactors/
161
+ │ │ ├─ angry_cat_actor/
162
+ │ │ │ └─ angry_cat_actor.rb
68
163
 
69
- ```
70
- # Resynchoronize entries
71
- $ birdel synth
164
+ # Component structure random example
165
+ app/
166
+ ├─ ui/
167
+ │ ├─ bentries/
168
+ │ │ ├─ home/
169
+ │ │ │ ├─ home_component/
170
+ │ │ │ │ ├─ home_component.rb
171
+ │ │ │ │ ├─ home_component.js
172
+ │ │ │ │ ├─ home_component.css
173
+ │ │ │ │ ├─ home_component_controller.js
174
+ │ │ │ │ └─ home_component_actor.js
175
+ │ ├─ mix/
176
+ │ │ ├─ home/
177
+ │ │ │ ├─ top_bar_component/
178
+ │ │ │ │ ├─ top_bar_component.rb
179
+ │ │ │ │ ├─ top_bar_component.js
180
+ │ │ │ │ ├─ top_bar_component.css
181
+ │ │ │ │ ├─ top_bar_component_controller.js
182
+ │ │ │ │ └─ top_bar_component_actor.js
72
183
  ```
73
184
 
74
- ```
75
- # precomponents.json example
185
+
186
+
187
+ ```ruby
188
+ # app/assets/stylesheets/ui/home/precomponents.json
76
189
 
77
190
  [
78
- "ui/birdel/fantasy",
191
+ "ui/birdel/dropdown",
79
192
  "ui/birdel/layout"
80
193
  ]
81
194
 
82
- # components.json example
195
+ # app/assets/stylesheets/ui/home/components.css.json
83
196
  [
84
- "ui/bentries/home_component/home_component",
85
- "ui/mix/mini_product_component/mini_product_component"
197
+ "ui/bentries/home/home_component/home_component",
198
+ "ui/mix/home/mini_product_component/mini_product_component"
86
199
  ]
87
- ```
88
-
89
- ## 📜 Request/Response specifications
90
200
 
91
- ```ruby
92
- #"actorDirect" and "actorThrough" - still an idea for some field
93
- #Request
94
- {
95
- "actor": "angry_cat_actor",
96
- "method": "process_order",
97
- "required_component": "ui--bars--top-bar-component",
98
- "inputs": {
99
- "customer": "John Doe",
100
- "items": [
101
- { "name": "Milk", "price": 1.5 },
102
- { "name": "Bread", "price": 2.5 }
103
- ]
104
- },
105
- "callback": {
106
- "actor": "angry_swallow_actor",
107
- "method": "process_bla",
108
- "inputs": {
109
- "customer": "John Doe",
110
- "items": [
111
- { "name": "Milk", "price": 1.5 },
112
- { "name": "Bread", "price": 2.5 }
113
- ]
114
- }
115
- }
116
- }
117
-
118
- #Response
119
- {
120
- "ok": true,
121
- "message": "Order processed successfully",
122
- "data": {
123
- "actor": "angry_cat_actor",
124
- "method": "process_order",
125
- "outputs": {
126
- "order_id": 1234,
127
- "total_amount": 4.0,
128
- },
129
- "html": "<div></div>",
130
- }
131
- }
132
- ```
133
-
134
- ## Actor
135
-
136
- ```ruby
137
- class AngryCatActor::AngryCatActor < Birdel::BaseActor
138
- def initialize()
139
- end
140
- def process_order
141
-
142
- end
143
- end
201
+ # app/views/layouts/ui/bentries/home/index.html.erb
202
+ ...
203
+ <%= stylesheet_link_tag "ui/bentries/home/index", "data-turbo-track": "reload" %>
204
+ <%= javascript_include_tag "ui/bentries/home/index", "data-turbo-track": "reload", defer: true, type: "module" %>
205
+ ...
144
206
  ```
145
207
 
146
208
  ## Actor Specification example
data/lib/birdel/cli.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'thor'
2
+
3
+ module Birdel
4
+ class CLI < Thor
5
+ desc "gcom NAME", "Generate a new component"
6
+ def gcom(name)
7
+ Birdel::Com.roll(name)
8
+ end
9
+
10
+ desc "synth", "Syncronize components assets"
11
+ def synth
12
+ Birdel::Synth.roll(name)
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,68 @@
1
+ module Birdel
2
+ module Com
3
+ def roll
4
+ app_path = Pathname.new("#{Dir.pwd}")
5
+ components_path = app_path.join("app", "components")
6
+ component_ns = ARGV[0]
7
+ component_ns_camelized = component_ns.split("::").map(&:camelize).join("::")
8
+ component_name = component_ns_camelized.split("::").last
9
+ component_path = component_ns.split("::").join("/")
10
+ full_component_path = components_path.join(component_path.underscore)
11
+
12
+ variable_name = "css_class"
13
+ css_class = component_ns_camelized.underscore.gsub('_', '-').gsub('/', '--')
14
+ actor_name = "#{component_name}Actor"
15
+ files = [
16
+ {
17
+ name: "#{component_name.underscore}.rb",
18
+ content: "
19
+ class #{component_ns_camelized}::#{component_name} < ViewComponent::Base
20
+ include Birdel::Component
21
+ end
22
+ "
23
+ },
24
+ { name: "#{component_name.underscore}.css", content: ".#{css_class}{}" },
25
+ { name: "#{component_name.underscore}.js", content: "" },
26
+ {
27
+ name: "#{component_name.underscore}_controller.js",
28
+ content: "
29
+ import { #{actor_name} } from \"./#{component_name.underscore}_actor\";
30
+ import { Controller } from \"@hotwired/stimulus\";
31
+ export default class extends Controller {
32
+ connect() {}
33
+ }
34
+ " },
35
+ {
36
+ name: "#{component_name.underscore}_actor.js",
37
+ content: "
38
+ import { ActorBase } from \"birdeljs\"
39
+ export class #{actor_name} extends ActorBase {
40
+ constructor() {
41
+ console.log(\"#{actor_name}!\");
42
+ }
43
+ }
44
+ "},
45
+ { name: "#{component_name.underscore}.html.erb", content: "<div class=\"<%= #{variable_name} %>\" data-controller=\"<%= #{variable_name} %>\">\n</div>" },
46
+ ]
47
+
48
+ files.each do |file|
49
+ file_path = full_component_path.join(file[:name])
50
+ if file_path.exist?
51
+ puts "File already exists: #{file_path}".red
52
+ else
53
+ puts "Creating file: #{file_path}".yellow
54
+ #create new file and folders if needed
55
+ file_path.dirname.mkpath
56
+ File.open(file_path, "w") do |f|
57
+ f.puts file[:content]
58
+ end
59
+ if file_path.exist?
60
+ puts "Done!".bold.green
61
+ else
62
+ puts "Failed".red
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+ end
@@ -0,0 +1,7 @@
1
+ module Birdel
2
+ module Component
3
+ def css_class
4
+ self.class.name.underscore.gsub('_', '-').gsub('/', '--').split('--')[0..-2].join('--')
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,116 @@
1
+
2
+ module Birdel
3
+ module Map
4
+ def roll(entry_ns)
5
+ myapp_path = Pathname.new("#{Dir.pwd}")
6
+ stylesheets_path = myapp_path.join("app", "assets", "stylesheets")
7
+ javascript_path = myapp_path.join("app", "javascript")
8
+ layouts_path = myapp_path.join("app", "views", "layouts")
9
+ css_bentries_path = stylesheets_path.join("ui", "bentries")
10
+ js_bentries_path = javascript_path.join("ui", "bentries")
11
+ layouts_bentries_path = layouts_path.join("ui", "bentries")
12
+
13
+ entry_ns_camelized = entry_ns.split("::").map(&:camelize).join("::")
14
+ entry_name = entry_ns_camelized.split("::").last
15
+ entry_path = entry_ns.split("::").join("/")
16
+
17
+ full_css_entry_path = css_bentries_path.join(entry_path.underscore)
18
+ full_js_entry_path = js_bentries_path.join(entry_path.underscore)
19
+ full_layout_entry_path = layouts_bentries_path.join(entry_path.underscore)
20
+
21
+ if full_css_entry_path.exist?
22
+ puts "Entry #{full_css_entry_path.relative_path_from(myapp_path)} already exists".red.bold
23
+ else
24
+ full_css_entry_path.mkpath
25
+ css_entry_files = [
26
+ { name: "components.css", content: "" },
27
+ { name: "components.css.json", content: "[]" },
28
+ { name: "precomponents.css", content: "" },
29
+ { name: "precomponents.css.json", content: "[]" },
30
+ { name: "index.css", content: "@import url(\"./components.css\");" },
31
+ ]
32
+ css_entry_files.each do |file|
33
+ if full_css_entry_path.join(file[:name]).exist?
34
+ puts "File #{full_css_entry_path.join(file[:name]).relative_path_from(myapp_path)} already exists".red.bold
35
+ else
36
+ puts full_css_entry_path.join(file[:name]).to_s.green.bold
37
+ full_css_entry_path.join(file[:name]).open("w") do |f|
38
+ f.write(file[:content])
39
+ end
40
+ end
41
+ end
42
+ end
43
+
44
+ if full_js_entry_path.exist?
45
+ puts "Entry #{full_js_entry_path.relative_path_from(myapp_path)} already exists".red.bold
46
+ else
47
+ full_js_entry_path.mkpath
48
+ js_entry_files = [
49
+ { name: "components.js", content: "" },
50
+ { name: "components.js.json", content: "[]" },
51
+ { name: "precomponents.js", content: "" },
52
+ { name: "precomponents.js.json", content: "[]" },
53
+ { name: "index.js", content: "import \"./components\";"},
54
+ ]
55
+ js_entry_files.each do |file|
56
+ if full_js_entry_path.join(file[:name]).exist?
57
+ puts "File #{full_js_entry_path.join(file[:name]).relative_path_from(myapp_path)} already exists".red.bold
58
+ else
59
+ puts "+ #{full_js_entry_path.join(file[:name]).relative_path_from(myapp_path).to_s}".green.bold
60
+ full_js_entry_path.join(file[:name]).open("w") do |f|
61
+ f.write(file[:content])
62
+ end
63
+ end
64
+ end
65
+ end
66
+
67
+ css_index_path = full_css_entry_path.join("index.css").relative_path_from(stylesheets_path)
68
+ js_index_path = full_js_entry_path.join("index.js").relative_path_from(javascript_path)
69
+
70
+ js_index_directory_path = js_index_path.dirname.to_s
71
+ js_index_filename_without_extension = js_index_path.basename('.js').to_s
72
+ js_index_formatted_path = "#{js_index_directory_path}/#{js_index_filename_without_extension}"
73
+
74
+ css_index_directory_path = css_index_path.dirname.to_s
75
+ css_index_filename_without_extension = css_index_path.basename('.css').to_s
76
+ css_index_formatted_path = "#{css_index_directory_path}/#{css_index_filename_without_extension}"
77
+
78
+
79
+ if full_layout_entry_path.exist?
80
+ puts "Entry #{full_layout_entry_path.relative_path_from(myapp_path)} already exists".red.bold
81
+ else
82
+ full_layout_entry_path.mkpath
83
+ layout_entry_files = [
84
+ { name: "index.html.erb", content: "
85
+ <!DOCTYPE html>
86
+ <html>
87
+ <head>
88
+ <meta name=\"viewport\" content=\"width=device-width,initial-scale=1, maximum-scale=1.0, user-scalable=no\" >
89
+ <%= action_cable_meta_tag %>
90
+ <%= csrf_meta_tags %>
91
+ <%= csp_meta_tag %>
92
+ <%= display_meta_tags %>
93
+ <%= stylesheet_link_tag \"#{css_index_formatted_path}\", \"data-turbo-track\": \"reload\" %>
94
+ <%= javascript_include_tag \"#{js_index_formatted_path}\", \"data-turbo-track\": \"reload\", defer: true, type: \"module\" %>
95
+ </head>
96
+
97
+ <body>
98
+ <%= yield %>
99
+ </body>
100
+ </html>
101
+ " },
102
+ ]
103
+ layout_entry_files.each do |file|
104
+ if full_layout_entry_path.join(file[:name]).exist?
105
+ puts "File #{full_layout_entry_path.join(file[:name]).relative_path_from(myapp_path)} already exists".red.bold
106
+ else
107
+ puts "+ #{full_layout_entry_path.join(file[:name]).relative_path_from(myapp_path).to_s}".green.bold
108
+ full_layout_entry_path.join(file[:name]).open("w") do |f|
109
+ f.write(file[:content])
110
+ end
111
+ end
112
+ end
113
+ end
114
+ end
115
+ end
116
+ end
@@ -1,7 +1,7 @@
1
1
  # Routing Overlay Network Actor
2
2
  module Birdel
3
3
  module Rona
4
- def actorDirect(data)
4
+ def actorThrough(data)
5
5
  actor_name = data.fetch("actor")
6
6
  inputs = data.fetch("inputs")
7
7
  callback = data.fetch("callback")
@@ -32,5 +32,24 @@ module Birdel
32
32
  ActionCable.server.broadcast(self.first_stream, res)
33
33
  end
34
34
  end
35
+
36
+ def actorDirect(data)
37
+ inputs = data.fetch("inputs")
38
+ callback = data.fetch("callback")
39
+ required_component = data.fetch("required_component")
40
+ component_name = required_component.split('--').map{|i| i.gsub("-", "_").camelize}.join('::') + '::' + required_component.split('--').last.gsub("-", "_").camelize
41
+ component = component_name.constantize.new(inputs: inputs)
42
+ res = {
43
+ "ok": true,
44
+ "message": "Actor Direct",
45
+ "data": {
46
+ "outputs": inputs,
47
+ "html": ApplicationController.render(component, layout: false)
48
+ }
49
+ }
50
+ res[:callback] = callback
51
+ res[:callback][:resourceId] = callback[:resource_id]
52
+ ActionCable.server.broadcast(self.first_stream, res)
53
+ end
35
54
  end
36
55
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Birdel
4
- VERSION = "0.3.2"
4
+ VERSION = "1.0.0"
5
5
  end
data/lib/birdel.rb CHANGED
@@ -5,16 +5,13 @@ require 'colored'
5
5
  require 'active_support/inflector'
6
6
 
7
7
  require_relative "birdel/version"
8
- # require_relative "birdel/com/com"
9
- # require_relative "birdel/map/map"
10
8
  require_relative "birdel/rona/rona_actor"
11
9
  require_relative "birdel/synth/synth_actor"
12
-
10
+ require_relative "birdel/com/com_actor"
11
+ require_relative "birdel/map/map_actor"
12
+ require_relative "birdel/component/component_actor"
13
13
  module Birdel
14
14
  class Error < StandardError; end
15
15
  class << self
16
- def test1
17
- puts "Birdel is a gem for sending messages to your actors and getting view_components back!"
18
- end
19
16
  end
20
17
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: birdel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Serhii
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-03-24 00:00:00.000000000 Z
11
+ date: 2023-05-04 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Send json messages to your actors and get view_components back! Now you
14
14
  can be sure that your actors are processed correctly.
@@ -29,8 +29,10 @@ files:
29
29
  - Rakefile
30
30
  - esbuild.config.js
31
31
  - lib/birdel.rb
32
- - lib/birdel/com/com.rb
33
- - lib/birdel/map/map.rb
32
+ - lib/birdel/cli.rb
33
+ - lib/birdel/com/com_actor.rb
34
+ - lib/birdel/component/component_actor.rb
35
+ - lib/birdel/map/map_actor.rb
34
36
  - lib/birdel/rona/rona_actor.rb
35
37
  - lib/birdel/synth/synth_actor.rb
36
38
  - lib/birdel/version.rb
@@ -1,63 +0,0 @@
1
- require "pathname"
2
- require 'active_support/inflector'
3
- require 'colored'
4
-
5
- class Birdel::Com
6
- def initialize
7
- end
8
-
9
- def roll
10
- app_path = Pathname.new("#{Dir.pwd}")
11
- components_path = app_path.join("app", "components")
12
- component_ns = ARGV[0]
13
- component_ns_camelized = component_ns.split("::").map(&:camelize).join("::")
14
- component_name = component_ns_camelized.split("::").last
15
- component_path = component_ns.split("::").join("/")
16
- full_component_path = components_path.join(component_path.underscore)
17
-
18
- variable_name = "css_class"
19
- css_class = component_ns_camelized.underscore.gsub('_', '-').gsub('/', '--')
20
- actor_name = "#{component_name.gsub("Component", "")}Actor"
21
- files = [
22
- { name: "#{component_name.underscore}.rb", content: "class #{component_ns_camelized}::#{component_name} < ViewComponent::Base\nend" },
23
- { name: "#{component_name.underscore}.css", content: ".#{css_class}{}" },
24
- { name: "#{component_name.underscore}.js", content: "" },
25
- { name: "#{component_name.underscore}_controller.js", content: "
26
- import { Controller } from \"@hotwired/stimulus\";
27
-
28
- export default class extends Controller {
29
- connect() {
30
- console.log(\"Hello, component!\");
31
- }
32
- }
33
- " },
34
- { name: "#{component_name.underscore}_actor.js", content: "
35
- export class #{actor_name}{
36
- constructor() {
37
- console.log(\"Hi, #{actor_name}!\");
38
- }
39
- }
40
- " },
41
- { name: "#{component_name.underscore}.html.erb", content: "<div class=\"<%= #{variable_name} %>\" data-controller=\"<%= #{variable_name} %>\">\n</div>" },
42
- ]
43
-
44
- files.each do |file|
45
- file_path = full_component_path.join(file[:name])
46
- if file_path.exist?
47
- puts "File already exists: #{file_path}".red
48
- else
49
- puts "Creating file: #{file_path}".yellow
50
- #create new file and folders if needed
51
- file_path.dirname.mkpath
52
- File.open(file_path, "w") do |f|
53
- f.puts file[:content]
54
- end
55
- if file_path.exist?
56
- puts "Done!".bold.green
57
- else
58
- puts "Failed".red
59
- end
60
- end
61
- end
62
- end
63
- end
@@ -1,118 +0,0 @@
1
-
2
- class Birdel::Map
3
- def initialize
4
- end
5
-
6
- def roll
7
- myapp_path = Pathname.new("#{Dir.pwd}")
8
- stylesheets_path = myapp_path.join("app", "assets", "stylesheets")
9
- javascript_path = myapp_path.join("app", "javascript")
10
- layouts_path = myapp_path.join("app", "views", "layouts")
11
- css_bentries_path = stylesheets_path.join("ui", "bentries")
12
- js_bentries_path = javascript_path.join("ui", "bentries")
13
- layouts_bentries_path = layouts_path.join("ui", "bentries")
14
-
15
- entry_ns = ARGV[0]
16
- entry_ns_camelized = entry_ns.split("::").map(&:camelize).join("::")
17
- entry_name = entry_ns_camelized.split("::").last
18
- entry_path = entry_ns.split("::").join("/")
19
-
20
- full_css_entry_path = css_bentries_path.join(entry_path.underscore)
21
- full_js_entry_path = js_bentries_path.join(entry_path.underscore)
22
- full_layout_entry_path = layouts_bentries_path.join(entry_path.underscore)
23
-
24
- if full_css_entry_path.exist?
25
- puts "Entry #{full_css_entry_path.relative_path_from(myapp_path)} already exists".red.bold
26
- else
27
- full_css_entry_path.mkpath
28
- css_entry_files = [
29
- { name: "components.css", content: "" },
30
- { name: "components.css.json", content: "[]" },
31
- { name: "precomponents.css", content: "" },
32
- { name: "precomponents.css.json", content: "[]" },
33
- { name: "index.css", content: "@import url(\"./components.css\");" },
34
- ]
35
- css_entry_files.each do |file|
36
- if full_css_entry_path.join(file[:name]).exist?
37
- puts "File #{full_css_entry_path.join(file[:name]).relative_path_from(myapp_path)} already exists".red.bold
38
- else
39
- puts full_css_entry_path.join(file[:name]).to_s.green.bold
40
- full_css_entry_path.join(file[:name]).open("w") do |f|
41
- f.write(file[:content])
42
- end
43
- end
44
- end
45
- end
46
-
47
- if full_js_entry_path.exist?
48
- puts "Entry #{full_js_entry_path.relative_path_from(myapp_path)} already exists".red.bold
49
- else
50
- full_js_entry_path.mkpath
51
- js_entry_files = [
52
- { name: "components.js", content: "" },
53
- { name: "components.js.json", content: "[]" },
54
- { name: "precomponents.js", content: "" },
55
- { name: "precomponents.js.json", content: "[]" },
56
- { name: "index.js", content: "import \"./components\";"},
57
- ]
58
- js_entry_files.each do |file|
59
- if full_js_entry_path.join(file[:name]).exist?
60
- puts "File #{full_js_entry_path.join(file[:name]).relative_path_from(myapp_path)} already exists".red.bold
61
- else
62
- puts "+ #{full_js_entry_path.join(file[:name]).relative_path_from(myapp_path).to_s}".green.bold
63
- full_js_entry_path.join(file[:name]).open("w") do |f|
64
- f.write(file[:content])
65
- end
66
- end
67
- end
68
- end
69
-
70
- css_index_path = full_css_entry_path.join("index.css").relative_path_from(stylesheets_path)
71
- js_index_path = full_js_entry_path.join("index.js").relative_path_from(javascript_path)
72
-
73
- js_index_directory_path = js_index_path.dirname.to_s
74
- js_index_filename_without_extension = js_index_path.basename('.js').to_s
75
- js_index_formatted_path = "#{js_index_directory_path}/#{js_index_filename_without_extension}"
76
-
77
- css_index_directory_path = css_index_path.dirname.to_s
78
- css_index_filename_without_extension = css_index_path.basename('.css').to_s
79
- css_index_formatted_path = "#{css_index_directory_path}/#{css_index_filename_without_extension}"
80
-
81
-
82
- if full_layout_entry_path.exist?
83
- puts "Entry #{full_layout_entry_path.relative_path_from(myapp_path)} already exists".red.bold
84
- else
85
- full_layout_entry_path.mkpath
86
- layout_entry_files = [
87
- { name: "index.html.erb", content: "
88
- <!DOCTYPE html>
89
- <html>
90
- <head>
91
- <meta name=\"viewport\" content=\"width=device-width,initial-scale=1, maximum-scale=1.0, user-scalable=no\" >
92
- <%= action_cable_meta_tag %>
93
- <%= csrf_meta_tags %>
94
- <%= csp_meta_tag %>
95
- <%= display_meta_tags %>
96
- <%= stylesheet_link_tag \"#{css_index_formatted_path}\", \"data-turbo-track\": \"reload\" %>
97
- <%= javascript_include_tag \"#{js_index_formatted_path}\", \"data-turbo-track\": \"reload\", defer: true, type: \"module\" %>
98
- </head>
99
-
100
- <body>
101
- <%= yield %>
102
- </body>
103
- </html>
104
- " },
105
- ]
106
- layout_entry_files.each do |file|
107
- if full_layout_entry_path.join(file[:name]).exist?
108
- puts "File #{full_layout_entry_path.join(file[:name]).relative_path_from(myapp_path)} already exists".red.bold
109
- else
110
- puts "+ #{full_layout_entry_path.join(file[:name]).relative_path_from(myapp_path).to_s}".green.bold
111
- full_layout_entry_path.join(file[:name]).open("w") do |f|
112
- f.write(file[:content])
113
- end
114
- end
115
- end
116
- end
117
- end
118
- end