loco-rails-core 0.1.1 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +70 -11
- data/lib/generators/loco/core/file_injector/file_injector_generator.rb +2 -7
- data/lib/loco/core/helpers.rb +2 -4
- data/lib/loco/core/version.rb +1 -1
- metadata +24 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 26dfb688861249f6eab817d589b6c2f4de7bae1fcb05218db33d69617940c741
|
4
|
+
data.tar.gz: 7514dd2f4ba4b8581a20e45cfe9d9a15925db01890ed2190c930cd88e396a629
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e82d8feab942392d9e8bdd8344a00feb7f8a8c95e254c7b005ade84e93c5c9b594fea5b35e89faaf26f6cb3933ef7d0d1fd5baac17b493bb9a3c66c83621c342
|
7
|
+
data.tar.gz: 8b3bb24380d95d267d55f08bad9a1b0bc6d7873d236a71ececb329f046b3e223e12c0eb36175910c7b48d5f6f6761a8faa1b26a2f6f1bbc4d97fc8c8317a675b
|
data/README.md
CHANGED
@@ -1,28 +1,87 @@
|
|
1
|
-
|
2
|
-
Short description and motivation.
|
1
|
+
![logo](https://raw.githubusercontent.com/artofcodelabs/artofcodelabs.github.io/master/assets/ext/loco_logo_trans_sqr-300px.png)
|
3
2
|
|
4
|
-
|
5
|
-
|
3
|
+
# 🧐 What is Loco-Rails-Core?
|
4
|
+
|
5
|
+
**Loco-Rails-Core** is a Rails plugin that has been extracted from [Loco-Rails](https://github.com/locoframework/loco-rails).
|
6
|
+
The reason for this extraction was to pull out functionality that can be used as a stand-alone lib.
|
7
|
+
This functionality was the origin of the [Loco-Rails](https://github.com/locoframework/loco-rails) project.
|
8
|
+
|
9
|
+
I wanted to provide a logical structure for a JavaScript code that corresponds to Rails` controllers and views.
|
10
|
+
The same controller's action that renders a response for a given request on the [Rails](https://rubyonrails.org) side would be called on the JavaScript level.
|
11
|
+
By _"the same"_ - I mean action with the same name and defined in an (optionally namespaced) controller with the corresponding name as the one on the server-side.
|
12
|
+
|
13
|
+
The **Loco-Rails-Core**, by itself, does not provide a lot of value. It should be used with its JavaScript complementary library - [Loco-JS-Core](https://github.com/locoframework/loco-js-core).
|
14
|
+
**Loco-Rails-Core**'s single generator adds `Loco::Core::Helpers` module to `ApplicationHelper`.
|
15
|
+
It also updates the `application.html.erb` layout by adding `data-*` attributes to HTML `<body>` element.
|
16
|
+
**Loco-Rails-Core** does this via methods defined in the mentioned above `Loco::Core::Helpers` module.
|
17
|
+
|
18
|
+
These attributes store the information about the namespace, controller, and action names involved in handing a given request.
|
19
|
+
[Loco-JS-Core](https://github.com/locoframework/loco-js-core) looks at these attributes to call out a method from the corresponding location but inside the JavaScript code.
|
20
|
+
In other words - [Loco-JS-Core](https://github.com/locoframework/loco-js-core) calls a JavaScript controller's action with the same name and located inside the same namespace.
|
21
|
+
|
22
|
+
_Example:_
|
23
|
+
|
24
|
+
Given that the `index` action from `Main::PagesControllers` handles a given request.
|
25
|
+
`<body>`'s data attributes are gonna look like this:
|
26
|
+
|
27
|
+
```html
|
28
|
+
<body data-namespace="Main" data-controller="Pages" data-action="index">
|
29
|
+
</body>
|
30
|
+
```
|
31
|
+
|
32
|
+
**Loco-JS-Core** will act similarly (simplified version):
|
33
|
+
|
34
|
+
```javascript
|
35
|
+
// all JavaScript controllers are assigned to the Controllers object
|
36
|
+
|
37
|
+
namespaceController = new Controllers.Main;
|
38
|
+
namespaceController.initialize();
|
39
|
+
|
40
|
+
controller = new Controllers.Main.Pages;
|
41
|
+
controller.initialize();
|
42
|
+
controller.index();
|
43
|
+
```
|
44
|
+
|
45
|
+
If you don't define a namespace controller - it will be skipped.
|
46
|
+
If you don't define an `initialize` or `index` actions - **Loco-JS-Core** won't call them.
|
47
|
+
You can define JavaScript counterparts only for those actions that you want to augment with JavaScript features.
|
48
|
+
|
49
|
+
**Loco-Rails-Core** is the right choice if you don't need all features that [Loco-Rails](https://github.com/locoframework/loco-rails) provides.
|
50
|
+
|
51
|
+
|
52
|
+
# 📥 Installation
|
6
53
|
|
7
|
-
## Installation
|
8
54
|
Add this line to your application's Gemfile:
|
9
55
|
|
10
56
|
```ruby
|
11
57
|
gem 'loco-rails-core'
|
12
58
|
```
|
13
|
-
|
14
59
|
And then execute:
|
60
|
+
|
15
61
|
```bash
|
16
62
|
$ bundle
|
17
63
|
```
|
18
64
|
|
19
|
-
|
65
|
+
|
66
|
+
# 🎮 Usage
|
67
|
+
|
20
68
|
```bash
|
21
|
-
$
|
69
|
+
$ bin/rails generate loco:core:file_injector
|
22
70
|
```
|
23
71
|
|
24
|
-
## Contributing
|
25
|
-
Contribution directions go here.
|
26
72
|
|
27
|
-
|
73
|
+
# 👩🏽🔬 Tests
|
74
|
+
|
75
|
+
```bash
|
76
|
+
$ bin/test
|
77
|
+
```
|
78
|
+
|
79
|
+
|
80
|
+
# 📜 License
|
81
|
+
|
28
82
|
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
83
|
+
|
84
|
+
|
85
|
+
# 👨🏭 Author
|
86
|
+
|
87
|
+
Zbigniew Humeniuk from [Art of Code](https://artofcode.co)
|
@@ -4,7 +4,7 @@ module Loco
|
|
4
4
|
module Core
|
5
5
|
class FileInjectorGenerator < Rails::Generators::Base
|
6
6
|
def application_helper
|
7
|
-
file_path = Rails.root.join
|
7
|
+
file_path = Rails.root.join('app/helpers/application_helper.rb')
|
8
8
|
line = %( include Loco::Core::Helpers\n)
|
9
9
|
inject_into_file file_path, line, after: "module ApplicationHelper\n"
|
10
10
|
end
|
@@ -19,12 +19,7 @@ module Loco
|
|
19
19
|
end
|
20
20
|
|
21
21
|
def layout_path
|
22
|
-
Rails.root.join(
|
23
|
-
'app',
|
24
|
-
'views',
|
25
|
-
'layouts',
|
26
|
-
'application.html.erb'
|
27
|
-
)
|
22
|
+
Rails.root.join('app/views/layouts/application.html.erb')
|
28
23
|
end
|
29
24
|
end
|
30
25
|
end
|
data/lib/loco/core/helpers.rb
CHANGED
@@ -4,13 +4,11 @@ module Loco
|
|
4
4
|
module Core
|
5
5
|
module Helpers
|
6
6
|
def loco_body_data
|
7
|
-
data_controller = controller_name.split('_').map(&:capitalize).join
|
7
|
+
data_controller = controller_name.split('_').map(&:capitalize).join
|
8
8
|
{
|
9
9
|
'data-namespace' => namespace_name,
|
10
10
|
'data-controller' => data_controller,
|
11
|
-
'data-action' => action_name
|
12
|
-
'data-rails-env' => Rails.env,
|
13
|
-
'data-user-agent' => request.user_agent
|
11
|
+
'data-action' => action_name
|
14
12
|
}
|
15
13
|
end
|
16
14
|
|
data/lib/loco/core/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: loco-rails-core
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zbigniew Humeniuk
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-03-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -30,71 +30,71 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: 3.
|
33
|
+
version: 3.38.0
|
34
34
|
type: :development
|
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: 3.
|
40
|
+
version: 3.38.0
|
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:
|
47
|
+
version: 6.1.1
|
48
48
|
type: :development
|
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:
|
54
|
+
version: 6.1.1
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rubocop
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '1.48'
|
62
62
|
type: :development
|
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: '
|
68
|
+
version: '1.48'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- - "
|
73
|
+
- - "~>"
|
74
74
|
- !ruby/object:Gem::Version
|
75
|
-
version:
|
75
|
+
version: 2.18.0
|
76
76
|
type: :development
|
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:
|
82
|
+
version: 2.18.0
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
84
|
name: selenium-webdriver
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - "~>"
|
88
88
|
- !ruby/object:Gem::Version
|
89
|
-
version:
|
89
|
+
version: 4.8.1
|
90
90
|
type: :development
|
91
91
|
prerelease: false
|
92
92
|
version_requirements: !ruby/object:Gem::Requirement
|
93
93
|
requirements:
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
|
-
version:
|
97
|
-
description: It enhances
|
96
|
+
version: 4.8.1
|
97
|
+
description: It enhances layout's body element with attributes containing information
|
98
98
|
about the current namespace, controller and action.
|
99
99
|
email:
|
100
100
|
- hello@artofcode.co
|
@@ -115,7 +115,8 @@ licenses:
|
|
115
115
|
- MIT
|
116
116
|
metadata:
|
117
117
|
allowed_push_host: https://rubygems.org
|
118
|
-
|
118
|
+
rubygems_mfa_required: 'true'
|
119
|
+
post_install_message:
|
119
120
|
rdoc_options: []
|
120
121
|
require_paths:
|
121
122
|
- lib
|
@@ -123,15 +124,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
123
124
|
requirements:
|
124
125
|
- - ">="
|
125
126
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
127
|
+
version: 3.0.0
|
127
128
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
128
129
|
requirements:
|
129
130
|
- - ">="
|
130
131
|
- !ruby/object:Gem::Version
|
131
132
|
version: '0'
|
132
133
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
134
|
-
signing_key:
|
134
|
+
rubygems_version: 3.4.6
|
135
|
+
signing_key:
|
135
136
|
specification_version: 4
|
136
|
-
summary:
|
137
|
+
summary: The core part of the Loco framework. It needs Loco-JS to work.
|
137
138
|
test_files: []
|