loco-rails-core 0.1.1 → 0.2.0
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 +1 -3
- data/lib/loco/core/version.rb +1 -1
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a1b9b27d3833f479412e2468bc55a09f807efd1da6d4c1e5bfd49d43759820c4
|
4
|
+
data.tar.gz: 3c01e866a531feb3809f809627f7560d5e3486e185c6c4a33e9c32285659a166
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3209f52b8b481143698234bea1f5df5dba6588d274c9e6b13fe3e893337b135fcd1e4e1004965a6c857272a0132d19bbd338b167fbbb1eaac9a6d4f9046fac02
|
7
|
+
data.tar.gz: 040b754199dd232da1c98381bf702edd7c80c578ff008487a0debb55a21cab93924019370ad83070c16cea094a04b718dfabbc1461871073860a1ab3aff50853
|
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 the 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 JavaScript code that would be corresponding with Rails` controllers and views.
|
10
|
+
The same controller's action would be called on the JavaScript level that renders a response for a given request on the [Rails](https://rubyonrails.org) side.
|
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 has to be used with its JavaScript complementary library - [Loco-JS](https://github.com/locoframework/loco-js).
|
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 aforementioned `Loco::Core::Helpers` module.
|
17
|
+
|
18
|
+
These attributes store the information about namespace, controller and action names involved in handing a given request.
|
19
|
+
[Loco-JS](https://github.com/locoframework/loco-js) looks at those attributes to call out method from the corresponding location but inside the JavaScript code.
|
20
|
+
In other words - [Loco-JS](https://github.com/locoframework/loco-js) will call 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** will act in the similar fashion (simplified version):
|
33
|
+
|
34
|
+
```javascript
|
35
|
+
import { Controllers } from "loco-js";
|
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 controlller - it will be skipped.
|
46
|
+
If you don't define an `initialize` or `index` actions - **Loco-JS** won't call them.
|
47
|
+
You can define a JavaScript counterparts only for those actions that you want to augment with JavaScript features.
|
48
|
+
|
49
|
+
**Loco-Rails-Core** is a good choice if you don't need all the 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
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.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Zbigniew Humeniuk
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-07-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -94,7 +94,7 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '3.142'
|
97
|
-
description: It enhances
|
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
|
@@ -130,8 +130,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
130
130
|
- !ruby/object:Gem::Version
|
131
131
|
version: '0'
|
132
132
|
requirements: []
|
133
|
-
rubygems_version: 3.
|
133
|
+
rubygems_version: 3.1.2
|
134
134
|
signing_key:
|
135
135
|
specification_version: 4
|
136
|
-
summary:
|
136
|
+
summary: The core part of the Loco framework. It needs Loco-JS to work.
|
137
137
|
test_files: []
|