remove_data_attributes 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 8f452b99f8cf397d4fe5847d5ba2acc358b0a4f9
4
+ data.tar.gz: 6fd3924500e127fbea0e3e24a7aaafd10c1f0921
5
+ SHA512:
6
+ metadata.gz: 1f9ef7647b704567c48f3f48e2b99754e14b5e8f3787c6aa64d19b8e183b2eec07eb345ccb28573f769172a57ca9fb815943d1cad51721c958962c3c8ee98278
7
+ data.tar.gz: 2a8ed8b6044246b76c13d4d13e1ddfb92d0d7a605ba8e2597617199679db79735351de888a57c8012fc5892a743bd675c4c68196ed27b26fc0d948ce9f2061af
data/CHANGELOG.md ADDED
@@ -0,0 +1,3 @@
1
+ # CHANGELOG
2
+ ## [0.1.0](https://github.com/yasaichi/remove_data_attributes/releases/tag/v0.1.0) (December 10, 2017)
3
+ * The initial release to reserve the gem name
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2017 yasaichi
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,28 @@
1
+ # RemoveDataAttributes
2
+ Short description and motivation.
3
+
4
+ ## Usage
5
+ How to use my plugin.
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'remove_data_attributes'
12
+ ```
13
+
14
+ And then execute:
15
+ ```bash
16
+ $ bundle
17
+ ```
18
+
19
+ Or install it yourself as:
20
+ ```bash
21
+ $ gem install remove_data_attributes
22
+ ```
23
+
24
+ ## Contributing
25
+ Contribution directions go here.
26
+
27
+ ## License
28
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,24 @@
1
+ # frozen_string_literal: true
2
+
3
+ begin
4
+ require "bundler/setup"
5
+ rescue LoadError
6
+ puts "You must `gem install bundler` and `bundle install` to run rake tasks"
7
+ end
8
+
9
+ require "rdoc/task"
10
+
11
+ RDoc::Task.new(:rdoc) do |rdoc|
12
+ rdoc.rdoc_dir = "rdoc"
13
+ rdoc.title = "RemoveDataAttributes"
14
+ rdoc.options << "--line-numbers"
15
+ rdoc.rdoc_files.include("README.md")
16
+ rdoc.rdoc_files.include("lib/**/*.rb")
17
+ end
18
+
19
+
20
+
21
+
22
+
23
+
24
+ require "bundler/gem_tasks"
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RemoveDataAttributes
4
+ class << self
5
+ attr_writer :configuration
6
+
7
+ def configuration
8
+ @configuration ||= ::RemoveDataAttributes::Configuration.new
9
+ end
10
+
11
+ def configure
12
+ yield(configuration) if block_given?
13
+ end
14
+ end
15
+
16
+ class Configuration
17
+ attr_writer :data_attributes
18
+
19
+ def data_attributes
20
+ @data_attributes ||= []
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "set"
4
+ require "active_support"
5
+ require "active_support/core_ext/string/inflections"
6
+
7
+ module RemoveDataAttributes
8
+ class Processor
9
+ DATA_ATTRIBUTE_KEYS = ["data", :data].freeze
10
+ DATA_ATTRIBUTE_PATTERN = /\Adata-(?<attribute_name>.+)\z/
11
+
12
+ def initialize(data_attributes)
13
+ valid_attribute_names = Array(data_attributes)
14
+ .map(&DATA_ATTRIBUTE_PATTERN.method(:match))
15
+ .select(&:itself)
16
+ .map { |md| md[:attribute_name] }
17
+
18
+ @target_keys = valid_attribute_names.map { |name| "data-#{name}" }.to_set
19
+ @target_keys_in_nested_hash = valid_attribute_names.map(&method(:normalize)).to_set
20
+ end
21
+
22
+ def call(hash)
23
+ new_hash = hash.reject { |key, _| @target_keys.include?(key.to_s) }
24
+
25
+ DATA_ATTRIBUTE_KEYS.each do |key|
26
+ nested_hash = hash[key]
27
+ next unless nested_hash.is_a?(::Hash)
28
+
29
+ new_hash[key] = nested_hash
30
+ .reject { |key, _| @target_keys_in_nested_hash.include?(normalize(key)) }
31
+ end
32
+
33
+ new_hash
34
+ end
35
+
36
+ private
37
+
38
+ # :reek:UtilityFunction
39
+ def normalize(attribute_name)
40
+ attribute_name.to_s.dasherize
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/lazy_load_hooks"
5
+ require "rails/railtie"
6
+ require "remove_data_attributes/configuration"
7
+ require "remove_data_attributes/tag_options_filter"
8
+
9
+ module RemoveDataAttributes
10
+ class Railtie < ::Rails::Railtie
11
+ config.after_initialize do
12
+ ::ActiveSupport.on_load(:action_view) do
13
+ patch = ::RemoveDataAttributes::TagOptionsFilter[
14
+ ::RemoveDataAttributes.configuration.data_attributes
15
+ ]
16
+
17
+ if Gem::Version.new(Rails.version) < Gem::Version.new("5.1")
18
+ ::ActionView::Helpers::TagHelper.include(patch)
19
+ else
20
+ ::ActionView::Helpers::TagHelper::TagBuilder.include(patch)
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "active_support"
4
+ require "active_support/concern"
5
+ require "remove_data_attributes/processor"
6
+
7
+ module RemoveDataAttributes
8
+ module TagOptionsFilter
9
+ class << self
10
+ def [](data_attributes)
11
+ module_cache[data_attributes] ||= module_for(data_attributes)
12
+ end
13
+
14
+ private
15
+
16
+ def module_cache
17
+ @module_cache ||= {}
18
+ end
19
+
20
+ def module_for(data_attributes)
21
+ method_name = :tag_options
22
+ processor = ::RemoveDataAttributes::Processor.new(data_attributes)
23
+
24
+ ::Module.new do
25
+ extend ::ActiveSupport::Concern
26
+
27
+ included do |klass|
28
+ patch = Module.new do
29
+ define_method(method_name) do |options, escape = true|
30
+ options.is_a?(::Hash) ?
31
+ super(processor.call(options), escape) : super(options, escape)
32
+ end
33
+
34
+ private method_name if klass.private_method_defined?(method_name)
35
+ end
36
+
37
+ klass.prepend(patch)
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RemoveDataAttributes
4
+ VERSION = "0.1.0"
5
+ end
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "remove_data_attributes/configuration"
4
+ require "remove_data_attributes/railtie"
5
+ require "remove_data_attributes/version"
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+ # desc "Explaining what the task does"
3
+ # task :remove_data_attributes do
4
+ # # Task goes here
5
+ # end
metadata ADDED
@@ -0,0 +1,140 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: remove_data_attributes
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - yasaichi
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-12-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 4.0.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: 4.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: appraisal
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: reek
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sqlite3
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ description: Rails plugin enables you to remove data attributes automatically from
98
+ views.
99
+ email:
100
+ - yasaichi@users.noreply.github.com
101
+ executables: []
102
+ extensions: []
103
+ extra_rdoc_files: []
104
+ files:
105
+ - CHANGELOG.md
106
+ - MIT-LICENSE
107
+ - README.md
108
+ - Rakefile
109
+ - lib/remove_data_attributes.rb
110
+ - lib/remove_data_attributes/configuration.rb
111
+ - lib/remove_data_attributes/processor.rb
112
+ - lib/remove_data_attributes/railtie.rb
113
+ - lib/remove_data_attributes/tag_options_filter.rb
114
+ - lib/remove_data_attributes/version.rb
115
+ - lib/tasks/remove_data_attributes_tasks.rake
116
+ homepage: https://github.com/yasaichi/remove_data_attributes
117
+ licenses:
118
+ - MIT
119
+ metadata: {}
120
+ post_install_message:
121
+ rdoc_options: []
122
+ require_paths:
123
+ - lib
124
+ required_ruby_version: !ruby/object:Gem::Requirement
125
+ requirements:
126
+ - - ">="
127
+ - !ruby/object:Gem::Version
128
+ version: '0'
129
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ requirements: []
135
+ rubyforge_project:
136
+ rubygems_version: 2.5.2.1
137
+ signing_key:
138
+ specification_version: 4
139
+ summary: Rails plugin for removing data attributes from views
140
+ test_files: []