vuejs_form_for 0.1.1

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: 96d7d5d18f53b8a125b2d127d56d45691c661f34
4
+ data.tar.gz: 934a6a6c20847a560be9bd9cfcebdd89c46d3c59
5
+ SHA512:
6
+ metadata.gz: ce75c924c2d9497ce23fa5e61d95ed530bca786ffbf3e054e12837f2951c16ab93c3f4bd1aa1bb4a32e70809879e7500de535df0f626f8e8e9807bbba0edcc0a
7
+ data.tar.gz: 796087cefb5c6dc077e6d8162c735629f5777268f27c91c45a7a8d4e92573d4bc60b18f3c89129ecfe068fd6ba8a1d1ab5c2c3c9f37053e41f764b9fd74f2417
data/README.md ADDED
@@ -0,0 +1,41 @@
1
+ # VuejsFormFor
2
+
3
+ Welcome to your new gem! In this directory, you'll find the files you need to be able to package up your Ruby library into a gem. Put your Ruby code in the file `lib/vuejs_form_for`. To experiment with that code, run `bin/console` for an interactive prompt.
4
+
5
+ TODO: Delete this and the text above, and describe your gem
6
+
7
+ ## Installation
8
+
9
+ Add this line to your application's Gemfile:
10
+
11
+ ```ruby
12
+ gem 'vuejs_form_for'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install vuejs_form_for
22
+
23
+ ## Usage
24
+
25
+ TODO: Write usage instructions here
26
+
27
+ ## Development
28
+
29
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
30
+
31
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
32
+
33
+ ## Contributing
34
+
35
+ Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/vuejs_form_for. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
36
+
37
+
38
+ ## License
39
+
40
+ The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
41
+
@@ -0,0 +1,14 @@
1
+ require "vuejs_form_for/version"
2
+ require "vuejs_form_for/form_builder"
3
+ require "vuejs_form_for/railtie"
4
+
5
+
6
+ begin
7
+ require "pry"
8
+ rescue LoadError
9
+ end
10
+
11
+ module VuejsFormFor
12
+ # Your code goes here...
13
+
14
+ end
@@ -0,0 +1,48 @@
1
+ require "./vue_options_resolver"
2
+
3
+ module VuejsFormFor
4
+ class FormBuilder < ActionView::Helpers::FormBuilder
5
+ include VuejsFormFor::VueOptionsResolver
6
+
7
+ (field_helpers - [:label, :check_box, :radio_button, :fields_for])
8
+ .each do |selector|
9
+ class_eval <<-RUBY_EVAL, __FILE__, __LINE__ + 1
10
+ def #{selector}(method, options = {})
11
+ resolve_vue_options(options)
12
+ namespace = @object_name.gsub(/\\[/, ".").gsub(/\\]/, "")
13
+ options[:"v-model"] ||= "\#{namespace}_\#{method}"
14
+ super(method, options)
15
+ end
16
+ RUBY_EVAL
17
+ end
18
+
19
+ def label(method, text = nil, options = {}, &block)
20
+ resolve_vue_options(options)
21
+ super(method, text, options, &block)
22
+ end
23
+
24
+ def check_box(method, options = {}, checked_value = "1", unchecked_value = "0")
25
+ resolve_vue_options(options)
26
+ namespace = @object_name.gsub(/\[/, ".").gsub(/\]/, "")
27
+ options[:"v-model"] ||= "#{namespace}.#{method}"
28
+ super(method, options, checked_value, unchecked_value)
29
+ end
30
+
31
+ def radio_button(method, tag_value, options = {})
32
+ resolve_vue_options(options)
33
+ namespace = @object_name.gsub(/\[/, ".").gsub(/\]/, "")
34
+ options[:"v-model"] ||= "#{namespace}.#{method}"
35
+ super(method, tag_value, options)
36
+ end
37
+
38
+ def submit(value = nil, options = {})
39
+ resolve_vue_options(options)
40
+ super(value, options)
41
+ end
42
+
43
+ def button(value = nil, options = {}, &block)
44
+ resolve_vue_options(options)
45
+ super(value, options, &block)
46
+ end
47
+ end
48
+ end
@@ -0,0 +1,8 @@
1
+ module VuejsFormFor
2
+ module FormHelper
3
+ def vuejs_form_for(record, options = {}, &block)
4
+ options[:builder] ||= VuejsFormFor::FormBuilder
5
+ form_for(record, options, &block)
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,13 @@
1
+ require "vuejs_form_for/form_helper"
2
+ require "vuejs_form_for/tag_helper"
3
+
4
+ module VuejsFormFor
5
+ class Railtie < Rails::Railtie
6
+ initializer "vuejs_form_for.view_form_helper" do
7
+ ActiveSupport.on_load :action_view do
8
+ include VuejsFormFor::FormHelper
9
+ include VuejsFormFor::TagHelper
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,26 @@
1
+ require "./vue_options_resolver"
2
+
3
+ module VuejsFormFor
4
+ module TagHelper
5
+ include VuejsFormFor::VueOptionsResolver
6
+
7
+ def vue_tag(name, options = nil, open = false, escape = true)
8
+ resolve_vue_options(options) if options
9
+ tag(name, options, open, escape)
10
+ end
11
+
12
+ def vue_content_tag(name, content_or_options_with_block = nil, options = nil,
13
+ escape = true, &block)
14
+
15
+ if block_given?
16
+ if content_or_options_with_block.is_a?(Hash)
17
+ resolve_vue_options(content_or_options_with_block)
18
+ end
19
+ else
20
+ resolve_vue_options(options) if options
21
+ end
22
+
23
+ content_tag(name, content_or_options_with_block, options, escape, &block)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,4 @@
1
+ module VuejsFormFor
2
+ VERSION = "0.1.1"
3
+
4
+ end
@@ -0,0 +1,42 @@
1
+ module VuejsFormFor
2
+ module VueOptionsResolver
3
+ private def resolve_vue_options(options)
4
+ if options[:bind].kind_of?(Hash)
5
+ h = options.delete(:bind)
6
+ h.each do |key, value|
7
+ if value.kind_of?(String)
8
+ options[:"v-bind:#{key}"] = value
9
+ end
10
+ end
11
+ end
12
+
13
+ if options[:on].kind_of?(Hash)
14
+ h = options.delete(:on)
15
+ h.each do |key, value|
16
+ if value.kind_of?(String)
17
+ options[:"v-on:#{key}"] = value
18
+ end
19
+ end
20
+ end
21
+
22
+ %i(checked disabled multiple readonly selected).each do |attr_name|
23
+ if options[attr_name].kind_of?(String)
24
+ options[:"v-bind:#{attr_name}"] = options.delete(attr_name)
25
+ end
26
+ end
27
+
28
+ %i(text html show if else else_if for model).each do |directive|
29
+ if options[directive].kind_of?(String)
30
+ options[:"v-#{directive.to_s.dasherize}"] = options.delete(directive)
31
+ end
32
+ end
33
+
34
+ %i(pre cloak once).each do |directive|
35
+ if options[directive]
36
+ options.delete(directive)
37
+ options[:"v-#{directive}"] = "v-#{directive}"
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,11 @@
1
+ require "bundler/setup"
2
+ require "vuejs_form_for"
3
+
4
+ RSpec.configure do |config|
5
+ # Enable flags like --only-failures and --next-failure
6
+ config.example_status_persistence_file_path = ".rspec_status"
7
+
8
+ config.expect_with :rspec do |c|
9
+ c.syntax = :expect
10
+ end
11
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ RSpec.describe VuejsFormFor do
4
+ it "has a version number" do
5
+ expect(VuejsFormFor::VERSION).not_to be nil
6
+ end
7
+
8
+
9
+ end
metadata ADDED
@@ -0,0 +1,113 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: vuejs_form_for
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - nbtcnet
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2018-06-17 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
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
+ description: " just use vuejs_form_for instead of form_for"
70
+ email:
71
+ - hxmusic@foxmail.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - README.md
77
+ - lib/vuejs_form_for.rb
78
+ - lib/vuejs_form_for/form_builder.rb
79
+ - lib/vuejs_form_for/form_helper.rb
80
+ - lib/vuejs_form_for/railtie.rb
81
+ - lib/vuejs_form_for/tag_helper.rb
82
+ - lib/vuejs_form_for/version.rb
83
+ - lib/vuejs_form_for/vue_options_resolver.rb
84
+ - spec/spec_helper.rb
85
+ - spec/vuejs_form_for_spec.rb
86
+ homepage: https://github.com/TCnet/vuejs_form_for
87
+ licenses:
88
+ - MIT
89
+ metadata:
90
+ allowed_push_host: https://rubygems.org/
91
+ post_install_message:
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: '0'
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubyforge_project:
107
+ rubygems_version: 2.5.1
108
+ signing_key:
109
+ specification_version: 4
110
+ summary: a vue for form_for
111
+ test_files:
112
+ - spec/spec_helper.rb
113
+ - spec/vuejs_form_for_spec.rb