smart_buttons 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 697ad2e2668eda9a08807387a0a98533339f6be59ed431f1372f0a4e6302a66a
4
- data.tar.gz: ab810a26be67c346e339529686f3081693dc591b74e5e211d02febc7c95882bb
3
+ metadata.gz: 444a4eefa01c242b794d90c3a3b3e0a7d6f5be3891908eeced6b22025c813bce
4
+ data.tar.gz: bf6e28906dc51b9fa7f656c54854ce8bf08b24b1d7ef50aa2ad501ec95cfa1bf
5
5
  SHA512:
6
- metadata.gz: f0bcc6c5ebf5bbf69b2b7c95d5336bc50c387954ce7342ab4d0f68166b2d5849c26491babaf864c27714b389ee0bee3c9b7c24aed4335f2f5534f05294570708
7
- data.tar.gz: cc5386fa0cac1cfa3e61892309439830803e03f51b24a53463c36a8b9bcaa054770e5133d41c33af280760b2b15f8af03c8c3722b115c7f6af29ac242e77a50c
6
+ metadata.gz: f7b08104497bf07d7926b1cc1ec641ca70553950be5987a381c3edf8953cd8b1271fdc790e6010288de68a24ac1f4f8c08a876a7ac0d2e53cbef984c57e05a5a
7
+ data.tar.gz: 9872d2361adc8c51832f40910b8e9f4d4033ee31a5153f61cf876375daf389407731d60f6f31026965b4c5a935e300d9988ddafdeeb37b165faad1bf5efd172f
data/.gitignore CHANGED
@@ -9,3 +9,4 @@
9
9
 
10
10
  # rspec failure tracking
11
11
  .rspec_status
12
+ *.gem
@@ -1,17 +1,27 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- smart_buttons (0.1.0)
4
+ smart_buttons (1.0)
5
+ simple_form
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
10
+ actionpack (6.0.2.1)
11
+ actionview (= 6.0.2.1)
12
+ activesupport (= 6.0.2.1)
13
+ rack (~> 2.0, >= 2.0.8)
14
+ rack-test (>= 0.6.3)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
9
17
  actionview (6.0.2.1)
10
18
  activesupport (= 6.0.2.1)
11
19
  builder (~> 3.1)
12
20
  erubi (~> 1.4)
13
21
  rails-dom-testing (~> 2.0)
14
22
  rails-html-sanitizer (~> 1.1, >= 1.2.0)
23
+ activemodel (6.0.2.1)
24
+ activesupport (= 6.0.2.1)
15
25
  activesupport (6.0.2.1)
16
26
  concurrent-ruby (~> 1.0, >= 1.0.2)
17
27
  i18n (>= 0.7, < 2)
@@ -42,6 +52,9 @@ GEM
42
52
  pry (0.12.2)
43
53
  coderay (~> 1.1.0)
44
54
  method_source (~> 0.9.0)
55
+ rack (2.1.1)
56
+ rack-test (1.1.0)
57
+ rack (>= 1.0, < 3)
45
58
  rails-dom-testing (2.0.3)
46
59
  activesupport (>= 4.2.0)
47
60
  nokogiri (>= 1.6)
@@ -70,10 +83,13 @@ GEM
70
83
  ruby-progressbar (~> 1.7)
71
84
  unicode-display_width (>= 1.4.0, < 1.7)
72
85
  ruby-progressbar (1.10.1)
86
+ simple_form (5.0.1)
87
+ actionpack (>= 5.0)
88
+ activemodel (>= 5.0)
73
89
  thread_safe (0.3.6)
74
90
  tzinfo (1.2.6)
75
91
  thread_safe (~> 0.1)
76
- unicode-display_width (1.6.0)
92
+ unicode-display_width (1.6.1)
77
93
  zeitwerk (2.2.2)
78
94
 
79
95
  PLATFORMS
data/README.md CHANGED
@@ -1,7 +1,6 @@
1
- # SmartButtons
1
+ # SmartButtons [![Build Status](https://github.com/kalashnikovisme/smart_buttons/workflows/Ruby/badge.svg)](https://github.com/kalashnikovisme/smart_buttons/actions)
2
2
 
3
3
  Replacement of magical `link_to` method with static HTML
4
- TODO: Delete this and the text above, and describe your gem
5
4
 
6
5
  ## Installation
7
6
 
@@ -1,13 +1,10 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'smart_buttons/version'
4
+ require 'smart_buttons/patch_button'
5
+ require 'smart_buttons/delete_button'
4
6
 
5
7
  module SmartButtons
6
- def delete_button(url, form_options: {}, button_options: {})
7
- form_tag url, method: :delete, **form_options do
8
- button_tag(**button_options) do
9
- yield if block_given?
10
- end
11
- end
12
- end
8
+ include DeleteButton
9
+ include PatchButton
13
10
  end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartButtons::DeleteButton
4
+ def delete_button(url:, form_options: {}, button_options: {})
5
+ form_tag url, method: :delete, **form_options do
6
+ button_tag(**button_options) do
7
+ yield if block_given?
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,36 @@
1
+ # frozen_string_literal: true
2
+
3
+ module SmartButtons::PatchButton
4
+ def patch_button(**options)
5
+ simple_form_for options[:record], url: build_url(options), method: :patch, html: options[:form_options] do |f|
6
+ options[:attributes].each do |attr|
7
+ concat build_input attr, options, f
8
+ end
9
+ concat(button_tag(type: :submit, **options[:button_options]) do
10
+ yield if block_given?
11
+ end)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def build_url(options)
18
+ {
19
+ controller: options[:controller],
20
+ action: options[:action],
21
+ id: options[:record].id
22
+ }.merge(options[:parameters])
23
+ end
24
+
25
+ def build_input(attr, options, form)
26
+ form.input(
27
+ attr[0],
28
+ input_html: {
29
+ value: attr[1],
30
+ id: "#{options[:model_name]}_#{attr[0]}",
31
+ name: "#{options[:model_name]}[#{attr[0]}]"
32
+ },
33
+ as: :hidden
34
+ )
35
+ end
36
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module SmartButtons
4
- VERSION = '0.1.0'
4
+ VERSION = '1.0'
5
5
  end
@@ -1,4 +1,3 @@
1
-
2
1
  lib = File.expand_path("../lib", __FILE__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require "smart_buttons/version"
@@ -26,4 +25,6 @@ Gem::Specification.new do |spec|
26
25
  spec.add_development_dependency 'pry'
27
26
  spec.add_development_dependency 'actionview'
28
27
  spec.add_development_dependency 'rubocop'
28
+
29
+ spec.add_dependency 'simple_form'
29
30
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: smart_buttons
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: '1.0'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Kalashnikov
@@ -94,6 +94,20 @@ dependencies:
94
94
  - - ">="
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: simple_form
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
97
111
  description: Replacement of Rails `link_to` method with static HTML
98
112
  email:
99
113
  - kalashnikovisme@gmail.com
@@ -114,6 +128,8 @@ files:
114
128
  - bin/console
115
129
  - bin/setup
116
130
  - lib/smart_buttons.rb
131
+ - lib/smart_buttons/delete_button.rb
132
+ - lib/smart_buttons/patch_button.rb
117
133
  - lib/smart_buttons/version.rb
118
134
  - smart_buttons.gemspec
119
135
  homepage: https://github.com/kalashnikovisme/smart_buttons