rails-vue-helpers 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.travis.yml +6 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +127 -0
- data/Rakefile +10 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/lib/rails-vue-helpers/railtie.rb +11 -0
- data/lib/rails-vue-helpers/tag_helpers.rb +69 -0
- data/lib/rails-vue-helpers/version.rb +3 -0
- data/lib/rails-vue-helpers.rb +2 -0
- data/rails-vue-helpers.gemspec +26 -0
- metadata +86 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: afd0db3f28463bae72f7c7ae725ee14af62bfec326cf0cccb790025577b5a461
|
4
|
+
data.tar.gz: 515631b0e8484733d34cffe0c368681f325bd7f7136be0f056809490b618bb90
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 88cdcfbc2b89cc8594c252e4af3a1efa8f71b0fb16340d179b5323d5fcd756db75db2958b155d458ea755b7cfc007c91583c17eaa064e80a786b403b66e1faa4
|
7
|
+
data.tar.gz: 432849aa7759d818c71406a9d235eedef5d602c99034ac2b9ca114a52ba76ca6d936dfd6c4d781bafeea5c658566c934ef545d9c8325f266b93ccec4a9a67a83
|
data/.gitignore
ADDED
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2020 Lucas Hourquebie
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,127 @@
|
|
1
|
+
# Rails::Vue::Helpers
|
2
|
+
|
3
|
+
**VueHelpers** is a small gem developed by [Unagi](https://unagi.com.ar/) for Ruby on Rails applications. It has built-in helpers with [Vue.js](https://vuejs.org/) compatibility in order to use some of the most common Rails helpers with Vue.js directives.
|
4
|
+
|
5
|
+
The gem allows Rails applications extends the implementation of `link_to`, `content_tag` and `check_box_tag` in order to support Vue.js directives.
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
Add this line to your application's Gemfile:
|
10
|
+
|
11
|
+
```ruby
|
12
|
+
gem 'rails-vue-helpers'
|
13
|
+
```
|
14
|
+
|
15
|
+
And then execute:
|
16
|
+
|
17
|
+
$ bundle install
|
18
|
+
|
19
|
+
Or install it yourself as:
|
20
|
+
|
21
|
+
$ gem install rails-vue-helpers
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
This gem extends some of the most commons Rails helpers, so the original helpers can be used in the same the way as before without any modification.
|
26
|
+
|
27
|
+
However, if you'd like to add some Vue directives, you should use consider this gem syntax. The following options applies for all the helpers the gem provides, which at the present time are: `link_to`, `content_tag` and `check_box_tag`.
|
28
|
+
|
29
|
+
All the options are received as values of the `vue` key. This key is another option as `class` or `id`, which are officially supported by Rails helpers. So, a full example could be the next one:
|
30
|
+
|
31
|
+
```ruby
|
32
|
+
<%= link_to users_path,
|
33
|
+
class: 'btn btn-primary',
|
34
|
+
vue: {
|
35
|
+
bind: {class: "disabledUsersLink && 'disabled'"},
|
36
|
+
on: {click: "handleExportCookie('#{request.uuid}')"}
|
37
|
+
},
|
38
|
+
title: 'This action will redirect you to users list' do
|
39
|
+
%>
|
40
|
+
Go to users list
|
41
|
+
<% end %>
|
42
|
+
```
|
43
|
+
|
44
|
+
### v-bind
|
45
|
+
`v-bind` is used for one-way data binding. Whenever you need to add one or more `v-bind` directives on a tag, you could use the `binding` key inside the `vue` hash. Its value must be a hash: each key is an attribute binding, whereas its value is the associated binding evaluation.
|
46
|
+
|
47
|
+
```ruby
|
48
|
+
<%= link_to 'Users list', users_path,
|
49
|
+
class: 'btn btn-primary',
|
50
|
+
vue: {
|
51
|
+
bind: {
|
52
|
+
class: "disabledUsersLink && 'disabled'",
|
53
|
+
title: 'usersLinkTitle'
|
54
|
+
}
|
55
|
+
}
|
56
|
+
%>
|
57
|
+
```
|
58
|
+
|
59
|
+
### v-on
|
60
|
+
`v-bind` is used for events handling. If you need to use one or more `v-on` directives on a tag, you must use the `on` key inside the `vue` hash. Its value must be a hash: each key is an event name, whereas its value is the action it will perform when the event is listened.
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
<%= link_to 'Users list', users_path,
|
64
|
+
class: 'btn btn-primary',
|
65
|
+
vue: {
|
66
|
+
on: {
|
67
|
+
click: "handleExportCookie('#{request.uuid}')"},
|
68
|
+
mouseover: 'displayHint'
|
69
|
+
}
|
70
|
+
}
|
71
|
+
%>
|
72
|
+
```
|
73
|
+
|
74
|
+
### v-model
|
75
|
+
`v-model` directive is used for two-way data binding. This feature is available using the `model` key of the `vue` hash. Its value must be a string, which represents the evaluation of the `v-model`.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
<%= check_box_tag "customers_id[]",
|
79
|
+
customer.id,
|
80
|
+
false,
|
81
|
+
class: 'customers_id',
|
82
|
+
vue: {
|
83
|
+
model: 'selectedUsers'
|
84
|
+
}
|
85
|
+
%>
|
86
|
+
```
|
87
|
+
|
88
|
+
### Directives
|
89
|
+
Vue has a lot of directives, so the gem implements the `directives` key to support all of them. Directives like `v-show`, `v-if` or `v-for`, and even custom components directives can be used with this. In order to use it, you must set the `directives` key inside the `vue` hash. Its value must be a hash: each key is a directive, whereas its value is the associated data.
|
90
|
+
|
91
|
+
```ruby
|
92
|
+
<%= content_tag :span, '10% discount',
|
93
|
+
class: 'text-bold',
|
94
|
+
vue: {
|
95
|
+
directives: {
|
96
|
+
show: 'showCouponsForm'
|
97
|
+
}
|
98
|
+
}
|
99
|
+
%>
|
100
|
+
```
|
101
|
+
|
102
|
+
### Props
|
103
|
+
Components properties are available through the `props` key of the `vue` hash. Its value must be a hash: each key is a prop, and its value is property data.
|
104
|
+
|
105
|
+
```ruby
|
106
|
+
<%= content_tag :select2, '',
|
107
|
+
vue: {
|
108
|
+
props: {
|
109
|
+
ajax: '/users/autocomplete',
|
110
|
+
placeholder: 'Search...',
|
111
|
+
name: 'filter[user_id]'
|
112
|
+
}
|
113
|
+
}
|
114
|
+
%>
|
115
|
+
```
|
116
|
+
|
117
|
+
## Development
|
118
|
+
|
119
|
+
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).
|
120
|
+
|
121
|
+
## Contributing
|
122
|
+
|
123
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/lucashour/rails-vue-helpers.
|
124
|
+
|
125
|
+
## License
|
126
|
+
|
127
|
+
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "rails/vue/helpers"
|
5
|
+
|
6
|
+
# You can add fixtures and/or initialization code here to make experimenting
|
7
|
+
# with your gem easier. You can also use a different console, if you like.
|
8
|
+
|
9
|
+
# (If you use this, don't forget to add pry to your Gemfile!)
|
10
|
+
# require "pry"
|
11
|
+
# Pry.start
|
12
|
+
|
13
|
+
require "irb"
|
14
|
+
IRB.start(__FILE__)
|
data/bin/setup
ADDED
@@ -0,0 +1,69 @@
|
|
1
|
+
module RailsVueHelpers
|
2
|
+
module TagHelpers
|
3
|
+
def link_to(name = nil, options = nil, html_options = nil, &block)
|
4
|
+
options = html_options unless block_given?
|
5
|
+
|
6
|
+
rails_tag_with_vue_data(super, options, :a)
|
7
|
+
end
|
8
|
+
|
9
|
+
def content_tag(name, content_or_options_with_block = nil, options = nil, escape = true, &block)
|
10
|
+
options = [content_or_options_with_block, options].find do |argument|
|
11
|
+
argument.is_a?(Hash)
|
12
|
+
end
|
13
|
+
|
14
|
+
rails_tag_with_vue_data(super, options)
|
15
|
+
end
|
16
|
+
|
17
|
+
def check_box_tag(name, value = '1', checked = false, options = {})
|
18
|
+
rails_tag_with_vue_data(super, options, :input)
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def rails_tag_with_vue_data(rails_tag, options, tag_name = nil)
|
24
|
+
regex = rails_tag[/<#{tag_name}.+?>/][/(?:(?!>).)*/]
|
25
|
+
|
26
|
+
rails_tag.gsub(regex, "\\0 #{vue_data(options)}").html_safe
|
27
|
+
end
|
28
|
+
|
29
|
+
def vue_data(options)
|
30
|
+
options ||= {}
|
31
|
+
attributes = (options[:vue] || options['vue'] || {}).stringify_keys
|
32
|
+
options = {}
|
33
|
+
|
34
|
+
(attributes['bind'] || {}).each do |key, value|
|
35
|
+
options[":#{key}"] = value
|
36
|
+
end
|
37
|
+
|
38
|
+
(attributes['on'] || {}).each do |key, value|
|
39
|
+
options["@#{key}"] = value
|
40
|
+
end
|
41
|
+
|
42
|
+
(attributes['directives'] || {}).each do |key, value|
|
43
|
+
options["v-#{key}"] = value.to_s
|
44
|
+
end
|
45
|
+
|
46
|
+
(attributes['props'] || {}).each do |key, value|
|
47
|
+
options[key] = value.to_s
|
48
|
+
end
|
49
|
+
|
50
|
+
if attributes['model']
|
51
|
+
options['v-model'] = attributes['model']
|
52
|
+
end
|
53
|
+
|
54
|
+
remove_quotation_marks(options)
|
55
|
+
tag_builder.tag_options(options)
|
56
|
+
end
|
57
|
+
|
58
|
+
def remove_quotation_marks(options)
|
59
|
+
options.each do |key, value|
|
60
|
+
return unless value
|
61
|
+
next if value[0] != "\""
|
62
|
+
next if value[-1] != "\""
|
63
|
+
|
64
|
+
value[0] = ''
|
65
|
+
value[-1] = ''
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require_relative 'lib/rails-vue-helpers/version'
|
2
|
+
|
3
|
+
Gem::Specification.new do |spec|
|
4
|
+
spec.name = 'rails-vue-helpers'
|
5
|
+
spec.version = RailsVueHelpers::VERSION
|
6
|
+
spec.authors = ['Lucas Hourquebie']
|
7
|
+
spec.email = ['lucashour1993@gmail.com']
|
8
|
+
|
9
|
+
spec.summary = 'Main Rails helpers extension to support Vue.js attributes'
|
10
|
+
spec.homepage = 'https://unagi.com.ar/'
|
11
|
+
spec.license = 'MIT'
|
12
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.3.0")
|
13
|
+
spec.metadata["allowed_push_host"] = 'https://rubygems.org'
|
14
|
+
|
15
|
+
# Specify which files should be added to the gem when it is released.
|
16
|
+
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
17
|
+
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
|
18
|
+
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
19
|
+
end
|
20
|
+
|
21
|
+
spec.required_ruby_version = ">= 2.3.0"
|
22
|
+
spec.add_dependency "actionview", ">= 4.2"
|
23
|
+
spec.add_dependency "railties", ">= 4.2"
|
24
|
+
|
25
|
+
spec.require_paths = ['lib']
|
26
|
+
end
|
metadata
ADDED
@@ -0,0 +1,86 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rails-vue-helpers
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Lucas Hourquebie
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2020-05-19 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: actionview
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '4.2'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '4.2'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: railties
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4.2'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '4.2'
|
41
|
+
description:
|
42
|
+
email:
|
43
|
+
- lucashour1993@gmail.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- ".gitignore"
|
49
|
+
- ".travis.yml"
|
50
|
+
- Gemfile
|
51
|
+
- LICENSE.txt
|
52
|
+
- README.md
|
53
|
+
- Rakefile
|
54
|
+
- bin/console
|
55
|
+
- bin/setup
|
56
|
+
- lib/rails-vue-helpers.rb
|
57
|
+
- lib/rails-vue-helpers/railtie.rb
|
58
|
+
- lib/rails-vue-helpers/tag_helpers.rb
|
59
|
+
- lib/rails-vue-helpers/version.rb
|
60
|
+
- rails-vue-helpers.gemspec
|
61
|
+
homepage: https://unagi.com.ar/
|
62
|
+
licenses:
|
63
|
+
- MIT
|
64
|
+
metadata:
|
65
|
+
allowed_push_host: https://rubygems.org
|
66
|
+
post_install_message:
|
67
|
+
rdoc_options: []
|
68
|
+
require_paths:
|
69
|
+
- lib
|
70
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - ">="
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: 2.3.0
|
75
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
version: '0'
|
80
|
+
requirements: []
|
81
|
+
rubyforge_project:
|
82
|
+
rubygems_version: 2.7.6
|
83
|
+
signing_key:
|
84
|
+
specification_version: 4
|
85
|
+
summary: Main Rails helpers extension to support Vue.js attributes
|
86
|
+
test_files: []
|