action_widget 0.8.0 → 0.10.0

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
- SHA1:
3
- metadata.gz: be79e5ca5532c6047d471857cfc5a8f7ee87410e
4
- data.tar.gz: 3cad04dc423d1a573671286cdcc104515aafec80
2
+ SHA256:
3
+ metadata.gz: 936309a17ec24cbcbbabbe95f6a2d1348eb938e7ad96ccb95ad94c81a4c00970
4
+ data.tar.gz: 25c23abdf0674deab60754b91e57cc44daa68484f2e573bb86bb75a255c616f5
5
5
  SHA512:
6
- metadata.gz: 5c52f486e2af4ebcc2c1634398cebcd0729acaed72c1ae02f0e8355efb2cda86b912546fb8d9a3747a9b9cbf15e456ab17cd9382ecb3ce0e809f66537fce3146
7
- data.tar.gz: b7efc419ade14ed4b9593ec035f99500bf73fe36fd2a4cddef59dea8148210855b98d205b5fdb199120f40d78875d5c2ed1140fde1423837c0c33af1fb3d410b
6
+ metadata.gz: 22099b7acd486464b24a8cbd18555fe2cff2dd236a885a43dad88a214aa7d47f441285a8d822a934aed64fde7d5490533a70e1722e0cf72bd259d3c2ea25ff7b
7
+ data.tar.gz: 376888ff223f362a863ef32cdc69d709286fd5439f92fda3dfe7c29698a388f84aeae36431822ce9f0ac7d44b5e869a2b95ecaf8e4a8e763d02129060705011f
@@ -0,0 +1,26 @@
1
+ name: Testing
2
+
3
+ on:
4
+ push:
5
+ branches: [master]
6
+ pull_request:
7
+ branches: [master]
8
+ workflow_dispatch:
9
+
10
+ jobs:
11
+ test:
12
+ name: Ruby v${{ matrix.ruby_version}}
13
+ runs-on: ubuntu-latest
14
+ strategy:
15
+ matrix:
16
+ ruby_version: [3.4.1]
17
+ steps:
18
+ - uses: actions/checkout@v2
19
+ - name: Set up Ruby
20
+ uses: ruby/setup-ruby@v1
21
+ with:
22
+ ruby-version: ${{ matrix.ruby_version }}
23
+ - name: Install dependencies
24
+ run: bundle install
25
+ - name: Run tests
26
+ run: bundle exec rake spec
data/README.md CHANGED
@@ -21,17 +21,39 @@ change.
21
21
 
22
22
  ## Installation
23
23
 
24
- Add this line to your application's Gemfile:
24
+ Add `ActionWidget` to your application by running
25
25
 
26
- gem 'action_widget'
26
+ $ bundle add action_widget
27
27
 
28
- And then execute:
28
+ or install it manually by running:
29
29
 
30
- $ bundle
30
+ $ gem install action_widget
31
31
 
32
- Or install it yourself as:
32
+ ### Ruby on Rails
33
33
 
34
- $ gem install action_widget
34
+ If you're working with Ruby on Rails, please run
35
+
36
+ $ bin/rails action_widget:install
37
+
38
+ in addition to one of the above commands to generate the initializer that allows
39
+ you to configure `ActionWidget`. The resulting initializer will be located at
40
+ `config/initializers/action_widget.rb` and should look as follows:
41
+
42
+ ```ruby
43
+ ActionWidget.configure do |config|
44
+ # config.class_prefix = ""
45
+ config.class_suffix = "Widget"
46
+
47
+ # config.helper_prefix = ""
48
+ config.helper_suffix = "widget"
49
+
50
+ config.directory = "widgets"
51
+ end
52
+ ```
53
+
54
+ As shown in the example above, `ActionWidget` allows you to customize
55
+ prefixes and suffixes for class names and helper names, respectively, as well as
56
+ specify the directory name that will house your widgets within the `app/` directory.
35
57
 
36
58
  ## Usage
37
59
 
@@ -1,24 +1,31 @@
1
- # -*- encoding: utf-8 -*-
2
- require File.expand_path('../lib/action_widget/version.rb', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ require File.expand_path('lib/action_widget/version.rb', __dir__)
3
4
 
4
5
  Gem::Specification.new do |gem|
5
- gem.authors = ["Konstantin Tennhard"]
6
- gem.email = ["me@t6d.de"]
7
- gem.summary = %q{Reusable view components for your Ruby web application}
8
- gem.homepage = "http://github.com/t6d/action_widget"
6
+ gem.authors = ['Konstantin Tennhard']
7
+ gem.email = ['me@t6d.de']
8
+ gem.summary = 'Reusable view components for your Ruby web application'
9
+ gem.homepage = 'http://github.com/t6d/action_widget'
9
10
 
10
- gem.files = `git ls-files`.split($\)
11
- gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
12
- gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
13
- gem.name = "action_widget"
14
- gem.require_paths = ["lib"]
15
- gem.version = ActionWidget::VERSION
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map { |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = 'action_widget'
15
+ gem.require_paths = ['lib']
16
+ gem.version = ActionWidget::VERSION
17
+ gem.required_ruby_version = '>= 3.0.0'
16
18
 
17
- gem.add_dependency 'smart_properties', '~> 1.10'
18
- gem.add_dependency 'activesupport', '> 2.2'
19
+ gem.add_dependency 'activesupport', '> 6.0'
20
+ gem.add_dependency 'smart_properties', '~> 1.12'
19
21
 
22
+ gem.add_development_dependency 'actionview', '>= 6.0'
20
23
  gem.add_development_dependency 'pry'
21
- gem.add_development_dependency 'rake', '~> 10.0'
22
- gem.add_development_dependency 'rspec', '~> 3.3'
23
- gem.add_development_dependency 'actionview', '~> 4.0'
24
+ gem.add_development_dependency 'rake'
25
+ gem.add_development_dependency 'rspec', '~> 3.13'
26
+ gem.add_development_dependency 'ruby-lsp'
27
+ gem.add_development_dependency 'ostruct'
28
+ gem.add_development_dependency 'mutex_m'
29
+ gem.add_development_dependency 'base64'
30
+ gem.add_development_dependency 'bigdecimal'
24
31
  end
@@ -18,7 +18,7 @@ module ActionWidget
18
18
  super(view, Hash[attributes])
19
19
  end
20
20
 
21
- def render
21
+ def render(*)
22
22
  raise NotImplementedError, "#{self.class} must implement #render"
23
23
  end
24
24
  end
@@ -1,34 +1,25 @@
1
1
  module ActionWidget
2
2
  class Configuration
3
3
  include SmartProperties
4
- property :prefix
5
- property :suffix
6
- property :superclass, required: true, default: -> { ActionWidget::Base }
7
- property :directory, required: true, converts: :to_s, accepts: ->(string) { !string.empty? }, default: -> { [underscored_prefix, underscored_suffix].compact.join("_") }
8
- property :minitest_superclass
9
4
 
10
- attr_reader :pattern
5
+ property :class_prefix
6
+ property :class_suffix, default: "Widget"
7
+ property :helper_prefix
8
+ property :helper_suffix, default: "widget"
9
+ property! :superclass, default: "ActionWidget::Base"
10
+ property! :directory,
11
+ converts: :to_s,
12
+ accepts: ->(string) { !string.empty? },
13
+ default: "widgets"
14
+ property! :minitest_superclass,
15
+ default: "ActionView::TestCase"
11
16
 
12
- def initialize(*)
13
- super
14
-
15
- @pattern = Regexp.new("^%s$" % [
16
- underscored_prefix,
17
- "(.*)",
18
- underscored_suffix
19
- ].compact.join("_"))
20
- end
21
-
22
- private
23
-
24
- def underscored_prefix
25
- return if prefix.nil?
26
- prefix.underscore
17
+ def class_pattern
18
+ Regexp.new("^%s$" % [class_prefix, "(.*?)", class_suffix].compact.join(""))
27
19
  end
28
20
 
29
- def underscored_suffix
30
- return if suffix.nil?
31
- suffix.underscore
21
+ def helper_pattern
22
+ Regexp.new("^%s$" % [helper_prefix, "(.*?)", helper_suffix].compact.join("_"))
32
23
  end
33
24
  end
34
25
  end
@@ -0,0 +1,19 @@
1
+ require "rails/generators"
2
+
3
+ module ActionWidget
4
+ class InitializerGenerator < Rails::Generators::Base
5
+ source_root File.expand_path('../../../../../support/templates', __FILE__)
6
+
7
+ def create_initializer_file
8
+ template "initializer.rb.erb", Rails.root.join("config", "initializers", "action_widget.rb")
9
+ end
10
+ end
11
+ end
12
+
13
+ namespace :action_widget do
14
+ desc "Install"
15
+ task :install do
16
+ require_relative './generators'
17
+ ActionWidget::InitializerGenerator.start
18
+ end
19
+ end
@@ -40,7 +40,7 @@ module ActionWidget
40
40
  end
41
41
 
42
42
  def test_filename
43
- "#{helper_name}_test.rb"
43
+ "#{filename}_test.rb"
44
44
  end
45
45
 
46
46
  def spec_path
@@ -48,7 +48,7 @@ module ActionWidget
48
48
  end
49
49
 
50
50
  def spec_filename
51
- "#{helper_name}_spec.rb"
51
+ "#{filename}_spec.rb"
52
52
  end
53
53
 
54
54
  def implementation_path
@@ -56,11 +56,15 @@ module ActionWidget
56
56
  end
57
57
 
58
58
  def implementation_filename
59
- "#{helper_name}.rb"
59
+ "#{filename}.rb"
60
+ end
61
+
62
+ def filename
63
+ [configuration.class_prefix&.underscore, basename.underscore, configuration.class_suffix&.underscore].compact.join('_')
60
64
  end
61
65
 
62
66
  def class_name
63
- [configuration.prefix, basename.classify, configuration.suffix].join('')
67
+ [configuration.class_prefix, basename.classify, configuration.class_suffix].compact.join('')
64
68
  end
65
69
 
66
70
  def superclass_name
@@ -68,15 +72,17 @@ module ActionWidget
68
72
  end
69
73
 
70
74
  def minitest_superclass_name
71
- (configuration.minitest_superclass || "ActionView::TestCase").to_s
75
+ configuration.minitest_superclass.to_s
72
76
  end
73
77
 
74
78
  def helper_name
75
- class_name.underscore
79
+ [configuration.helper_prefix, basename.underscore, configuration.helper_suffix].compact.join('_')
76
80
  end
77
81
 
78
82
  def basename
79
- if match = name.underscore.match(configuration.pattern)
83
+ if match = name.match(configuration.class_pattern)
84
+ match[1]
85
+ elsif match = name.match(configuration.helper_pattern)
80
86
  match[1]
81
87
  else
82
88
  name
@@ -4,8 +4,14 @@ module ActionWidget
4
4
  module Extensions
5
5
  module Rails
6
6
  class Railtie < ::Rails::Railtie
7
+ rake_tasks do
8
+ load File.expand_path("../action_widget_tasks.rake", __FILE__)
9
+ end
10
+
7
11
  initializer "action_widget.helper" do
8
- ActionView::Base.send(:include, ::ActionWidget::ViewHelper)
12
+ ActiveSupport.on_load(:action_view) do
13
+ include ActionWidget::ViewHelper
14
+ end
9
15
  end
10
16
  end
11
17
  end
@@ -1,3 +1,3 @@
1
1
  module ActionWidget
2
- VERSION = '0.8.0'
2
+ VERSION = '0.10.0'
3
3
  end
data/lib/action_widget.rb CHANGED
@@ -12,15 +12,11 @@ module ActionWidget
12
12
  end
13
13
 
14
14
  def configuration
15
- @configuration ||= Configuration.new(suffix: "Widget")
15
+ @configuration ||= Configuration.new
16
16
  end
17
17
 
18
18
  def configure(&block)
19
- @configuration = Configuration.new(&block)
20
- end
21
-
22
- def helper?(name)
23
- !!configuration.pattern.match(name)
19
+ @configuration = Configuration.new.tap(&block)
24
20
  end
25
21
 
26
22
  protected
@@ -38,9 +34,10 @@ module ActionWidget
38
34
  private
39
35
 
40
36
  def find_action_widget(helper_name)
41
- return nil unless helper?(helper_name)
42
- basename = configuration.pattern.match(helper_name)[1]
43
- classname = [configuration.prefix, basename.camelcase, configuration.suffix].join("")
37
+ match = configuration.helper_pattern.match(helper_name)
38
+ return nil if match.nil?
39
+ basename = match[1]
40
+ classname = [configuration.class_prefix, basename.classify, configuration.class_suffix].join("")
44
41
  classname.constantize
45
42
  rescue NameError, LoadError
46
43
  nil
@@ -18,14 +18,18 @@ class ViewContext < ActionView::Base
18
18
  end
19
19
 
20
20
  RSpec.describe ViewContext do
21
- subject(:view_context) { described_class.new }
21
+ subject(:view_context) { described_class.empty }
22
22
  it 'should implement #respond_to_missing?' do
23
23
  expect(view_context.send(:respond_to_missing?, :dummy_widget)).to eq(true)
24
24
  end
25
25
  end
26
26
 
27
27
  RSpec.describe DummyWidget do
28
- let(:view) { ViewContext.new }
28
+ let(:view) { ViewContext.empty }
29
+
30
+ it "should be registered" do
31
+ expect(ActionWidget[:dummy_widget]).to be(DummyWidget)
32
+ end
29
33
 
30
34
  it "should delegate unknown method calls to the view context" do
31
35
  expect(described_class.new(view).render).to eq("<p></p>")
@@ -49,4 +53,26 @@ RSpec.describe DummyWidget do
49
53
  expect(instance.options).to eq({class: 'wide'})
50
54
  end
51
55
  end
56
+
57
+ context "with custom configuration" do
58
+ let(:expected_html) { '<p>Hello World</p>' }
59
+
60
+ before do
61
+ ActionWidget.configure do |config|
62
+ config.helper_suffix = nil
63
+ end
64
+ end
65
+
66
+ it "should have an adjusted helper pattern" do
67
+ expect(ActionWidget.configuration.helper_pattern).to eq(/^(.*?)$/)
68
+ end
69
+
70
+ it "should be possible to override the helper suffix" do
71
+ expect(view.dummy("Hello World")).to eq(expected_html)
72
+ end
73
+
74
+ after do
75
+ ActionWidget.configure {}
76
+ end
77
+ end
52
78
  end
@@ -0,0 +1,9 @@
1
+ ActionWidget.configure do |config|
2
+ # config.class_prefix = nil
3
+ config.class_suffix = "Widget"
4
+
5
+ # config.helper_prefix = nil
6
+ config.helper_suffix = "widget"
7
+
8
+ # config.directory = "widgets"
9
+ end
metadata CHANGED
@@ -1,43 +1,56 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: action_widget
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Konstantin Tennhard
8
- autorequire:
9
8
  bindir: bin
10
9
  cert_chain: []
11
- date: 2015-11-19 00:00:00.000000000 Z
10
+ date: 2025-03-17 00:00:00.000000000 Z
12
11
  dependencies:
12
+ - !ruby/object:Gem::Dependency
13
+ name: activesupport
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ - - ">"
17
+ - !ruby/object:Gem::Version
18
+ version: '6.0'
19
+ type: :runtime
20
+ prerelease: false
21
+ version_requirements: !ruby/object:Gem::Requirement
22
+ requirements:
23
+ - - ">"
24
+ - !ruby/object:Gem::Version
25
+ version: '6.0'
13
26
  - !ruby/object:Gem::Dependency
14
27
  name: smart_properties
15
28
  requirement: !ruby/object:Gem::Requirement
16
29
  requirements:
17
30
  - - "~>"
18
31
  - !ruby/object:Gem::Version
19
- version: '1.10'
32
+ version: '1.12'
20
33
  type: :runtime
21
34
  prerelease: false
22
35
  version_requirements: !ruby/object:Gem::Requirement
23
36
  requirements:
24
37
  - - "~>"
25
38
  - !ruby/object:Gem::Version
26
- version: '1.10'
39
+ version: '1.12'
27
40
  - !ruby/object:Gem::Dependency
28
- name: activesupport
41
+ name: actionview
29
42
  requirement: !ruby/object:Gem::Requirement
30
43
  requirements:
31
- - - ">"
44
+ - - ">="
32
45
  - !ruby/object:Gem::Version
33
- version: '2.2'
34
- type: :runtime
46
+ version: '6.0'
47
+ type: :development
35
48
  prerelease: false
36
49
  version_requirements: !ruby/object:Gem::Requirement
37
50
  requirements:
38
- - - ">"
51
+ - - ">="
39
52
  - !ruby/object:Gem::Version
40
- version: '2.2'
53
+ version: '6.0'
41
54
  - !ruby/object:Gem::Dependency
42
55
  name: pry
43
56
  requirement: !ruby/object:Gem::Requirement
@@ -56,51 +69,107 @@ dependencies:
56
69
  name: rake
57
70
  requirement: !ruby/object:Gem::Requirement
58
71
  requirements:
59
- - - "~>"
72
+ - - ">="
60
73
  - !ruby/object:Gem::Version
61
- version: '10.0'
74
+ version: '0'
62
75
  type: :development
63
76
  prerelease: false
64
77
  version_requirements: !ruby/object:Gem::Requirement
65
78
  requirements:
66
- - - "~>"
79
+ - - ">="
67
80
  - !ruby/object:Gem::Version
68
- version: '10.0'
81
+ version: '0'
69
82
  - !ruby/object:Gem::Dependency
70
83
  name: rspec
71
84
  requirement: !ruby/object:Gem::Requirement
72
85
  requirements:
73
86
  - - "~>"
74
87
  - !ruby/object:Gem::Version
75
- version: '3.3'
88
+ version: '3.13'
76
89
  type: :development
77
90
  prerelease: false
78
91
  version_requirements: !ruby/object:Gem::Requirement
79
92
  requirements:
80
93
  - - "~>"
81
94
  - !ruby/object:Gem::Version
82
- version: '3.3'
95
+ version: '3.13'
83
96
  - !ruby/object:Gem::Dependency
84
- name: actionview
97
+ name: ruby-lsp
85
98
  requirement: !ruby/object:Gem::Requirement
86
99
  requirements:
87
- - - "~>"
100
+ - - ">="
88
101
  - !ruby/object:Gem::Version
89
- version: '4.0'
102
+ version: '0'
90
103
  type: :development
91
104
  prerelease: false
92
105
  version_requirements: !ruby/object:Gem::Requirement
93
106
  requirements:
94
- - - "~>"
107
+ - - ">="
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: ostruct
112
+ requirement: !ruby/object:Gem::Requirement
113
+ requirements:
114
+ - - ">="
115
+ - !ruby/object:Gem::Version
116
+ version: '0'
117
+ type: :development
118
+ prerelease: false
119
+ version_requirements: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ - !ruby/object:Gem::Dependency
125
+ name: mutex_m
126
+ requirement: !ruby/object:Gem::Requirement
127
+ requirements:
128
+ - - ">="
129
+ - !ruby/object:Gem::Version
130
+ version: '0'
131
+ type: :development
132
+ prerelease: false
133
+ version_requirements: !ruby/object:Gem::Requirement
134
+ requirements:
135
+ - - ">="
95
136
  - !ruby/object:Gem::Version
96
- version: '4.0'
97
- description:
137
+ version: '0'
138
+ - !ruby/object:Gem::Dependency
139
+ name: base64
140
+ requirement: !ruby/object:Gem::Requirement
141
+ requirements:
142
+ - - ">="
143
+ - !ruby/object:Gem::Version
144
+ version: '0'
145
+ type: :development
146
+ prerelease: false
147
+ version_requirements: !ruby/object:Gem::Requirement
148
+ requirements:
149
+ - - ">="
150
+ - !ruby/object:Gem::Version
151
+ version: '0'
152
+ - !ruby/object:Gem::Dependency
153
+ name: bigdecimal
154
+ requirement: !ruby/object:Gem::Requirement
155
+ requirements:
156
+ - - ">="
157
+ - !ruby/object:Gem::Version
158
+ version: '0'
159
+ type: :development
160
+ prerelease: false
161
+ version_requirements: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
98
166
  email:
99
167
  - me@t6d.de
100
168
  executables: []
101
169
  extensions: []
102
170
  extra_rdoc_files: []
103
171
  files:
172
+ - ".github/workflows/testing.yml"
104
173
  - ".gitignore"
105
174
  - ".travis.yml"
106
175
  - Gemfile
@@ -114,19 +183,20 @@ files:
114
183
  - lib/action_widget/extensions.rb
115
184
  - lib/action_widget/extensions/middleman.rb
116
185
  - lib/action_widget/extensions/rails.rb
186
+ - lib/action_widget/extensions/rails/action_widget_tasks.rake
117
187
  - lib/action_widget/extensions/rails/generators.rb
118
188
  - lib/action_widget/extensions/rails/railtie.rb
119
189
  - lib/action_widget/version.rb
120
190
  - lib/action_widget/view_helper.rb
121
191
  - spec/action_widget_spec.rb
122
192
  - spec/spec_helper.rb
193
+ - support/templates/initializer.rb.erb
123
194
  - support/templates/widget.rb.erb
124
195
  - support/templates/widget_spec.rb.erb
125
196
  - support/templates/widget_test.rb.erb
126
197
  homepage: http://github.com/t6d/action_widget
127
198
  licenses: []
128
199
  metadata: {}
129
- post_install_message:
130
200
  rdoc_options: []
131
201
  require_paths:
132
202
  - lib
@@ -134,19 +204,16 @@ required_ruby_version: !ruby/object:Gem::Requirement
134
204
  requirements:
135
205
  - - ">="
136
206
  - !ruby/object:Gem::Version
137
- version: '0'
207
+ version: 3.0.0
138
208
  required_rubygems_version: !ruby/object:Gem::Requirement
139
209
  requirements:
140
210
  - - ">="
141
211
  - !ruby/object:Gem::Version
142
212
  version: '0'
143
213
  requirements: []
144
- rubyforge_project:
145
- rubygems_version: 2.4.5
146
- signing_key:
214
+ rubygems_version: 3.6.2
147
215
  specification_version: 4
148
216
  summary: Reusable view components for your Ruby web application
149
217
  test_files:
150
218
  - spec/action_widget_spec.rb
151
219
  - spec/spec_helper.rb
152
- has_rdoc: