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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e80ca22fbbdff560a6bf1c412bd44ddda40621249e0a88da79a7c689cfe96374
4
- data.tar.gz: eb224b7a35ba9d5e638aa34b6100a33a796922edff6dccd158a2952553e82360
3
+ metadata.gz: 7531fb1b2668f9d7aa7fc2b76653f4f87638cbffb919d4fcc556192e14c87a5e
4
+ data.tar.gz: 34882f3cac0dbc33f6fbfcbebb9195c7564ffdd2e94a82145c7c76e4f8a24bea
5
5
  SHA512:
6
- metadata.gz: 1dcfa28c2753d30bcd99b8999122be6f9001be34aa2d2e0efafdb8bd3c57edc8165826a454c9c7d166e2817fc397d072e84d4f082ad994ac05d863f05aaa9ea2
7
- data.tar.gz: 673702ead1f88344bf279a0eb507c61a3e49fce8ad3b5153839bf83198a7ad166d898ead08dc5d4117cfd26b9ae7b8e33d44b4c4b7f65eab03c71ef95d8e7653
6
+ metadata.gz: be3f47247ba35d4ee29525eaa93ffee5025c605c4d585a7f7573e680a61d68ad43595e6ebf10ba8a79375f5aa9059577ec29161717cea1e2ffc02a5d2ffb3505
7
+ data.tar.gz: fe98c4fdab4bc3bf36c2e8748d695e725e4e6ab66bfbeb2c9f33d6c5657a009db5bcc02b197955fdd1b62a893ca7c42515f3bb343265b97564179570bc308dc1
data/.gitignore CHANGED
@@ -6,3 +6,4 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
+ /test/log/*.log
data/Gemfile CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  source "https://rubygems.org"
2
4
 
3
5
  # Specify your gem's dependencies in spark-component.gemspec
@@ -5,3 +7,4 @@ gemspec
5
7
 
6
8
  gem "pry-byebug", group: %i[development test]
7
9
  gem "rails", "~> 6.0.0"
10
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- spark-component (1.0.0.pre.alpha)
4
+ spark-component (1.0.0.pre.alpha.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
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(lib test)
8
- t.pattern = 'test/**/*_test.rb'
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(lib test)
13
- t.pattern = 'test/**/*_benchmark.rb'
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
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
2
3
 
3
4
  require "bundler/setup"
4
5
  require "spark/component"
@@ -12,3 +13,4 @@ require "spark/component"
12
13
 
13
14
  require "irb"
14
15
  IRB.start(__FILE__)
16
+
@@ -40,3 +40,4 @@ module Spark
40
40
  end
41
41
  end
42
42
  end
43
+
@@ -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.attr(:label)
37
- # some_instance.attr(:size)
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 attr(name)
75
- instance_variable_get(:"@#{name}")
73
+ def attribute(name)
74
+ attributes[name]
76
75
  end
77
76
 
78
77
  def attributes
79
- @attributes ||= {}
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
- # tag.div(data: attr_hash(:remote, :method)) { ... }
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
+
@@ -54,3 +54,4 @@ module Spark
54
54
  end
55
55
  end
56
56
  end
57
+
@@ -17,8 +17,15 @@ module Spark
17
17
  end
18
18
  end
19
19
 
20
- def initialize(attributes = nil)
21
- initialize_attributes(attributes)
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 set_element_attr_default(element, attrs = {})
70
- element_attr_default[element] = attrs
76
+ def set_element_attribute_default(element, attrs = {})
77
+ element_attribute_default[element] = attrs
71
78
  end
72
79
 
73
- def element_attr_default
74
- @element_attr_default ||= {}
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 merge_element_attr_default(name, attributes)
79
- attrs = element_attr_default[name]
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 = merge_element_attr_default(name, 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(attributes)
227
- initialize_attributes(attributes)
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
- call
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, &_block)
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
+
@@ -42,3 +42,4 @@ module Spark
42
42
  end
43
43
  end
44
44
  end
45
+
@@ -2,6 +2,7 @@
2
2
 
3
3
  module Spark
4
4
  module Component
5
- VERSION = "1.0.0-alpha".freeze
5
+ VERSION = "1.0.0.pre.alpha.1"
6
6
  end
7
7
  end
8
+
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require "spark/component/version"
2
4
  require "spark/component/element"
3
5
 
@@ -18,3 +20,4 @@ module Spark
18
20
  end
19
21
  end
20
22
  end
23
+
@@ -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 = %q{Add a Spark of awesome to your ActionView Component.}
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 = Dir.chdir(File.expand_path('..', __FILE__)) do
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-13 00:00:00.000000000 Z
11
+ date: 2019-11-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: actionview-component
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: '2.0'
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: '2.0'
26
+ version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
- name: actionview-component
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