lite-component 1.0.0 → 1.0.1
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 +4 -4
- data/CHANGELOG.md +7 -1
- data/Gemfile.lock +1 -1
- data/README.md +13 -0
- data/lib/lite/component/base.rb +1 -1
- data/lib/lite/component/element.rb +10 -4
- data/lib/lite/component/engine.rb +1 -9
- data/lib/lite/component/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a979993c0a2b4766c0d5bfd6d3eabac758a13e0d924e1e43ed3df23e03bd1b5b
|
4
|
+
data.tar.gz: d14ab8972d19321ea368f4c74f9f95b5edd86e0aad3feeb49912f41c82343579
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: efacdcc1d72ebc99b6a9d6898f638a57cfdb9ea94eb3ebef2bbfe1d0c95254fb741058f82f7a93fca39350f5eede02d69d1eb2d554cd8e7bd33ab0370ec3d59d
|
7
|
+
data.tar.gz: 8a92f51f05472a1958c34583fea0249169c75c0c3feeee7ebff5e86d122b472301721ba2ba50eda541499e27754c66d5bd69979af69ef2e5459a17eb6596c4be
|
data/CHANGELOG.md
CHANGED
@@ -6,6 +6,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
6
6
|
|
7
7
|
## [Unreleased]
|
8
8
|
|
9
|
-
## [1.0.
|
9
|
+
## [1.0.1] - 2019-12-13
|
10
|
+
### Added
|
11
|
+
- Included action view helpers and context
|
12
|
+
### Changed
|
13
|
+
- Renamed view variable to context to allow more action view includes
|
14
|
+
|
15
|
+
## [1.0.0] - 2019-12-12
|
10
16
|
### Added
|
11
17
|
- Initial project version
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -56,6 +56,7 @@ In the basic Rails app setup component `*.scss` and `*.js` will be automatically
|
|
56
56
|
via the tree lookup.
|
57
57
|
|
58
58
|
In order to require assets such manually require them in the manifest, e.g. `application.css`:
|
59
|
+
*Similar process for both CSS and JS*
|
59
60
|
|
60
61
|
```
|
61
62
|
/*
|
@@ -74,6 +75,18 @@ In order to require assets such manually require them in the manifest, e.g. `app
|
|
74
75
|
If you create a `ApplicationComponent` file in the `app/components` directory, the generator
|
75
76
|
will create file that inherit from `ApplicationComponent` if not `Lite::Component::Base`.
|
76
77
|
|
78
|
+
Components come with view helpers already included.
|
79
|
+
|
80
|
+
If you want to access route helpers in your components just include them like:
|
81
|
+
|
82
|
+
```ruby
|
83
|
+
# app/components/alert_component.rb
|
84
|
+
|
85
|
+
class AlertComponent < Components::Component
|
86
|
+
include Rails.application.routes.url_helpers
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
77
90
|
## Usage
|
78
91
|
|
79
92
|
### Attributes and blocks
|
data/lib/lite/component/base.rb
CHANGED
@@ -1,17 +1,23 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'action_view'
|
4
|
+
|
3
5
|
module Lite
|
4
6
|
module Component
|
5
7
|
class Element
|
6
8
|
|
7
9
|
include ActiveModel::Validations
|
10
|
+
include ActionView::Context
|
11
|
+
include ActionView::Helpers
|
12
|
+
|
13
|
+
attr_reader :context
|
8
14
|
|
9
|
-
def initialize(
|
15
|
+
def initialize(context, attributes = nil, &block)
|
10
16
|
initialize_attributes(attributes || {})
|
11
17
|
initialize_elements
|
12
18
|
|
13
|
-
@
|
14
|
-
@yield = block_given? ? @
|
19
|
+
@context = context
|
20
|
+
@yield = block_given? ? @context.capture(self, &block) : nil
|
15
21
|
|
16
22
|
validate!
|
17
23
|
rescue ActiveModel::ValidationError => e
|
@@ -42,7 +48,7 @@ module Lite
|
|
42
48
|
define_method_or_raise(name) do |attributes = nil, &block|
|
43
49
|
return get_instance_variable(multiple ? plural_name : name) unless attributes || block
|
44
50
|
|
45
|
-
element = self.class.elements[name][:class].new(
|
51
|
+
element = self.class.elements[name][:class].new(context, attributes, &block)
|
46
52
|
|
47
53
|
if multiple
|
48
54
|
get_instance_variable(plural_name) << element
|
@@ -6,9 +6,7 @@ module Lite
|
|
6
6
|
module Component
|
7
7
|
class Engine < ::Rails::Engine
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
initializer('lite-frontend.setup', group: :all) do |app|
|
9
|
+
initializer('lite-component.setup', group: :all) do |app|
|
12
10
|
app.paths['config'] << File.join(config.root, 'app')
|
13
11
|
app.paths['config'] << File.join(config.root, 'vendor')
|
14
12
|
end
|
@@ -17,12 +15,6 @@ module Lite
|
|
17
15
|
app.config.assets.paths << Lite::Component.path if app.config.respond_to?(:assets)
|
18
16
|
end
|
19
17
|
|
20
|
-
initializer('lite-component.view_helpers') do
|
21
|
-
ActiveSupport.on_load(:action_controller) do
|
22
|
-
helper Lite::Component::ComponentHelper
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
18
|
initializer('lite-component.view_paths') do
|
27
19
|
ActiveSupport.on_load(:action_controller) do
|
28
20
|
append_view_path Lite::Component.path
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lite-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Juan Gomez
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-12-
|
11
|
+
date: 2019-12-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|