spark-component 1.0.0.pre.alpha → 1.0.0.pre.alpha.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +1 -1
- data/Rakefile +5 -4
- data/bin/console +2 -0
- data/lib/spark/component/attr.rb +1 -0
- data/lib/spark/component/attribute.rb +7 -7
- data/lib/spark/component/classname.rb +1 -0
- data/lib/spark/component/element.rb +36 -16
- data/lib/spark/component/integration/action_view_component.rb +9 -2
- data/lib/spark/component/tag_attr.rb +1 -0
- data/lib/spark/component/version.rb +2 -1
- data/lib/spark/component.rb +3 -0
- data/spark-component.gemspec +6 -3
- metadata +12 -12
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7531fb1b2668f9d7aa7fc2b76653f4f87638cbffb919d4fcc556192e14c87a5e
|
4
|
+
data.tar.gz: 34882f3cac0dbc33f6fbfcbebb9195c7564ffdd2e94a82145c7c76e4f8a24bea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: be3f47247ba35d4ee29525eaa93ffee5025c605c4d585a7f7573e680a61d68ad43595e6ebf10ba8a79375f5aa9059577ec29161717cea1e2ffc02a5d2ffb3505
|
7
|
+
data.tar.gz: fe98c4fdab4bc3bf36c2e8748d695e725e4e6ab66bfbeb2c9f33d6c5657a009db5bcc02b197955fdd1b62a893ca7c42515f3bb343265b97564179570bc308dc1
|
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
data/Rakefile
CHANGED
@@ -4,13 +4,14 @@ require "bundler/gem_tasks"
|
|
4
4
|
require "rake/testtask"
|
5
5
|
|
6
6
|
Rake::TestTask.new(:test) do |t|
|
7
|
-
t.libs = %w
|
8
|
-
t.pattern =
|
7
|
+
t.libs = %w[lib test]
|
8
|
+
t.pattern = "test/**/*_test.rb"
|
9
9
|
end
|
10
10
|
|
11
11
|
Rake::TestTask.new(:bench) do |t|
|
12
|
-
t.libs = %w
|
13
|
-
t.pattern =
|
12
|
+
t.libs = %w[lib test]
|
13
|
+
t.pattern = "test/**/*_benchmark.rb"
|
14
14
|
end
|
15
15
|
|
16
16
|
task default: :test
|
17
|
+
|
data/bin/console
CHANGED
data/lib/spark/component/attr.rb
CHANGED
@@ -33,8 +33,8 @@ require "spark/component/tag_attr"
|
|
33
33
|
#
|
34
34
|
# Attributes can also be accessed with a helper method
|
35
35
|
#
|
36
|
-
# some_instance.
|
37
|
-
# some_instance.
|
36
|
+
# some_instance.attribute(:label)
|
37
|
+
# some_instance.attribute(:size)
|
38
38
|
#
|
39
39
|
# Extending a class will extend its attributes and their defaults.
|
40
40
|
#
|
@@ -66,17 +66,16 @@ module Spark
|
|
66
66
|
value = attrs[name] || (!default.nil? ? default : nil)
|
67
67
|
if set?(value)
|
68
68
|
instance_variable_set(:"@#{name}", value)
|
69
|
-
attributes[name] = value
|
70
69
|
end
|
71
70
|
end
|
72
71
|
end
|
73
72
|
|
74
|
-
def
|
75
|
-
|
73
|
+
def attribute(name)
|
74
|
+
attributes[name]
|
76
75
|
end
|
77
76
|
|
78
77
|
def attributes
|
79
|
-
|
78
|
+
attr_hash(*self.class.attributes.keys)
|
80
79
|
end
|
81
80
|
|
82
81
|
# Accepts an array of instance variables and returns
|
@@ -90,7 +89,7 @@ module Spark
|
|
90
89
|
#
|
91
90
|
# Example use case:
|
92
91
|
#
|
93
|
-
#
|
92
|
+
# <div data="<%= attr_hash(:remote, :method)) %>">
|
94
93
|
#
|
95
94
|
def attr_hash(*args)
|
96
95
|
args.each_with_object({}) do |name, obj|
|
@@ -195,3 +194,4 @@ module Spark
|
|
195
194
|
end
|
196
195
|
end
|
197
196
|
end
|
197
|
+
|
@@ -17,8 +17,15 @@ module Spark
|
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
|
-
def initialize(
|
21
|
-
|
20
|
+
def initialize(attrs = nil)
|
21
|
+
# Extract core element attributes
|
22
|
+
unless attrs.nil? || attrs.empty?
|
23
|
+
@_parent = attrs.delete(:_parent)
|
24
|
+
@_block = attrs.delete(:_block)
|
25
|
+
@view_context = attrs.delete(:_view)
|
26
|
+
end
|
27
|
+
|
28
|
+
initialize_attributes(attrs)
|
22
29
|
initialize_elements
|
23
30
|
super
|
24
31
|
end
|
@@ -26,7 +33,7 @@ module Spark
|
|
26
33
|
def render_self
|
27
34
|
return @content unless @content.nil?
|
28
35
|
|
29
|
-
@content = render_block(view_context, &_block)
|
36
|
+
@content = render_block(@view_context, &_block)
|
30
37
|
validate! if defined?(ActiveModel::Validations)
|
31
38
|
@content
|
32
39
|
end
|
@@ -66,17 +73,17 @@ module Spark
|
|
66
73
|
end
|
67
74
|
|
68
75
|
# Override the default value for an element's attribute(s)
|
69
|
-
def
|
70
|
-
|
76
|
+
def set_element_attribute_default(element, attrs = {})
|
77
|
+
element_attribute_default[element] = attrs
|
71
78
|
end
|
72
79
|
|
73
|
-
def
|
74
|
-
@
|
80
|
+
def element_attribute_default
|
81
|
+
@element_attribute_default ||= {}
|
75
82
|
end
|
76
83
|
|
77
84
|
# Merge user defined attributes with the overriden attributes of an element
|
78
|
-
def
|
79
|
-
attrs =
|
85
|
+
def merge_element_attribute_default(name, attributes)
|
86
|
+
attrs = element_attribute_default[name]
|
80
87
|
attributes = attrs.merge(attributes || {}) unless attrs.nil? || attrs.empty?
|
81
88
|
attributes
|
82
89
|
end
|
@@ -154,12 +161,15 @@ module Spark
|
|
154
161
|
define_method_if_able(name) do |attributes = nil, &block|
|
155
162
|
return get_element_variable(multiple ? plural : name) unless block || attributes
|
156
163
|
|
157
|
-
attributes
|
164
|
+
attributes ||= {}
|
165
|
+
attributes = merge_element_attribute_default(name, attributes)
|
166
|
+
attributes.merge!(
|
167
|
+
_parent: self,
|
168
|
+
_block: block,
|
169
|
+
_view: view_context
|
170
|
+
)
|
158
171
|
|
159
172
|
element = klass.new(attributes)
|
160
|
-
element._parent = self
|
161
|
-
element._block = block
|
162
|
-
element.view_context = view_context
|
163
173
|
|
164
174
|
# If element supports multiple instances, inject instance
|
165
175
|
# into array for later enumeration
|
@@ -183,6 +193,7 @@ module Spark
|
|
183
193
|
# If an element extends a component, extend that component's class and include the necessary modules
|
184
194
|
def extend_class(component, &config)
|
185
195
|
base = Class.new(component || Spark::Component::Element::Base, &config)
|
196
|
+
# base.include(Spark::Component::Element)
|
186
197
|
define_model_name(base) if defined?(ActiveModel)
|
187
198
|
|
188
199
|
return base unless component
|
@@ -221,13 +232,22 @@ module Spark
|
|
221
232
|
# Base class for non-component elements
|
222
233
|
class Base
|
223
234
|
include ActiveModel::Validations if defined?(ActiveModel)
|
224
|
-
include Spark::Component::Element
|
225
235
|
|
226
|
-
def initialize(
|
227
|
-
|
236
|
+
def initialize(attrs = nil)
|
237
|
+
# Extract core element attributes
|
238
|
+
unless attrs.nil? || attrs.empty?
|
239
|
+
@_parent = attrs.delete(:_parent)
|
240
|
+
@_block = attrs.delete(:_block)
|
241
|
+
@view_context = attrs.delete(:_view)
|
242
|
+
end
|
243
|
+
|
244
|
+
initialize_attributes(attrs)
|
228
245
|
initialize_elements
|
229
246
|
end
|
247
|
+
|
248
|
+
include Spark::Component::Element
|
230
249
|
end
|
231
250
|
end
|
232
251
|
end
|
233
252
|
end
|
253
|
+
|
@@ -20,15 +20,21 @@ module Spark
|
|
20
20
|
@lookup_context ||= view_context.lookup_context
|
21
21
|
@view_flow ||= view_context.view_flow
|
22
22
|
@virtual_path ||= virtual_path
|
23
|
+
@variant = @lookup_context.variants.first
|
24
|
+
old_current_template = @current_template
|
25
|
+
@current_template = self
|
23
26
|
|
24
27
|
# Pass self as a block parameter
|
25
28
|
@content = render_block(view_context, &block) if block_given?
|
26
29
|
validate!
|
27
|
-
|
30
|
+
|
31
|
+
send(self.class.call_method_name(@variant))
|
32
|
+
ensure
|
33
|
+
@current_template = old_current_template
|
28
34
|
end
|
29
35
|
|
30
36
|
def render_self
|
31
|
-
render_in(view_context,
|
37
|
+
render_in(@view_context, &@_block)
|
32
38
|
end
|
33
39
|
|
34
40
|
# Override class methods for components
|
@@ -64,3 +70,4 @@ module Spark
|
|
64
70
|
end
|
65
71
|
end
|
66
72
|
end
|
73
|
+
|
data/lib/spark/component.rb
CHANGED
data/spark-component.gemspec
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
lib = File.expand_path("lib", __dir__)
|
2
4
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
3
5
|
require "spark/component/version"
|
@@ -8,7 +10,7 @@ Gem::Specification.new do |spec|
|
|
8
10
|
spec.authors = ["Brandon Mathis"]
|
9
11
|
spec.email = ["brandon@imathis.com"]
|
10
12
|
|
11
|
-
spec.summary =
|
13
|
+
spec.summary = "Add a Spark of awesome to your ActionView Component."
|
12
14
|
spec.homepage = "https://github.com/spark-engine/component"
|
13
15
|
spec.license = "MIT"
|
14
16
|
|
@@ -20,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
20
22
|
|
21
23
|
# Specify which files should be added to the gem when it is released.
|
22
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
23
|
-
spec.files
|
25
|
+
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
24
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
25
27
|
end
|
26
28
|
|
@@ -28,11 +30,12 @@ Gem::Specification.new do |spec|
|
|
28
30
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
29
31
|
spec.require_paths = ["lib"]
|
30
32
|
|
31
|
-
spec.add_development_dependency "bundler", "~> 2.0"
|
32
33
|
spec.add_development_dependency "actionview-component"
|
34
|
+
spec.add_development_dependency "bundler", "~> 2.0"
|
33
35
|
spec.add_development_dependency "memory_profiler"
|
34
36
|
spec.add_development_dependency "minitest", "= 5.1.0"
|
35
37
|
spec.add_development_dependency "rake", "~> 10.0"
|
36
38
|
spec.add_development_dependency "rubocop"
|
37
39
|
spec.add_development_dependency "slim"
|
38
40
|
end
|
41
|
+
|
metadata
CHANGED
@@ -1,43 +1,43 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spark-component
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.0.pre.alpha
|
4
|
+
version: 1.0.0.pre.alpha.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brandon Mathis
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-11-
|
11
|
+
date: 2019-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
|
-
name:
|
14
|
+
name: actionview-component
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - "
|
17
|
+
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '0'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - "
|
24
|
+
- - ">="
|
25
25
|
- !ruby/object:Gem::Version
|
26
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: bundler
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0'
|
33
|
+
version: '2.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: '0'
|
40
|
+
version: '2.0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: memory_profiler
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|