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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 775fd8e9a6f315ab425672710cc83fa654b081909a670b4b849ec7b4753401b3
4
- data.tar.gz: 12b66c28eed78a0551d55596a2d0361d08da68c83e0c85cde7cdd9b50e57e963
3
+ metadata.gz: a979993c0a2b4766c0d5bfd6d3eabac758a13e0d924e1e43ed3df23e03bd1b5b
4
+ data.tar.gz: d14ab8972d19321ea368f4c74f9f95b5edd86e0aad3feeb49912f41c82343579
5
5
  SHA512:
6
- metadata.gz: cb132f66e10923ab98013677ccb5c0ec6a502c05895d45d7d91b8584da259e1f9211c87d965c7c960aa79884f7103d974b65a21386c28b68dfeb731bc46bf421
7
- data.tar.gz: cf33d78401b9eb07adba8ea39161a5d6166b0fcfb264c06d92e3c1acb89004ff23ad22304737156d12df8beefc1c36f0f2f4383b03447cbf8d50cde255375d8e
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.0] - 2019-12-10
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
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- lite-component (1.0.0)
4
+ lite-component (1.0.1)
5
5
  rails (>= 5.1.0)
6
6
 
7
7
  GEM
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
@@ -21,7 +21,7 @@ module Lite
21
21
  end
22
22
 
23
23
  def render
24
- @view.render(partial: to_partial_path, object: self)
24
+ context.render(partial: to_partial_path, object: self)
25
25
  end
26
26
 
27
27
  def to_partial_path
@@ -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(view, attributes = nil, &block)
15
+ def initialize(context, attributes = nil, &block)
10
16
  initialize_attributes(attributes || {})
11
17
  initialize_elements
12
18
 
13
- @view = view
14
- @yield = block_given? ? @view.capture(self, &block) : nil
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(@view, attributes, &block)
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
- isolate_namespace Lite::Component
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
@@ -3,7 +3,7 @@
3
3
  module Lite
4
4
  module Component
5
5
 
6
- VERSION ||= '1.0.0'
6
+ VERSION ||= '1.0.1'
7
7
 
8
8
  end
9
9
  end
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.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-12 00:00:00.000000000 Z
11
+ date: 2019-12-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails