rails_vue_helpers 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: a5e1805c87ecdbcf6302374c64a6ce1a136126ec
4
+ data.tar.gz: 6e94dd43863ba0e4fdf6241c4ff97712353082e7
5
+ SHA512:
6
+ metadata.gz: 490fb02f4362c1ede03b02c4edfb3705a2c631f438113a11bb20cd730a6707eb11b80233ece6acf974e6d215c491b577af5362a84274d4a9dbdc73a3306a0ad5
7
+ data.tar.gz: de849851ced6af6c9d41f2e61575f2ab23897c5b6761d5684e0b5e85621e9354b2ab129738ef7e498e56f75e977b62dbd50cd2b65fdec7f4d6b58d40f4495947
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.1
5
+ before_install: gem install bundler -v 1.16.0.pre.3
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at kristaps.kulikovskis@makit.lv. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "https://rubygems.org"
2
+
3
+ git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
4
+
5
+ # Specify your gem's dependencies in rails_vue_helpers.gemspec
6
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ rails_vue_helpers (0.1.0)
5
+ actionview (>= 4.1, < 6.0)
6
+ activesupport (>= 4.1, < 6.0)
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ actionview (5.1.5)
12
+ activesupport (= 5.1.5)
13
+ builder (~> 3.1)
14
+ erubi (~> 1.4)
15
+ rails-dom-testing (~> 2.0)
16
+ rails-html-sanitizer (~> 1.0, >= 1.0.3)
17
+ activesupport (5.1.5)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (~> 0.7)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ builder (3.2.3)
23
+ concurrent-ruby (1.0.5)
24
+ crass (1.0.3)
25
+ diff-lcs (1.3)
26
+ erubi (1.7.0)
27
+ i18n (0.9.5)
28
+ concurrent-ruby (~> 1.0)
29
+ loofah (2.2.0)
30
+ crass (~> 1.0.2)
31
+ nokogiri (>= 1.5.9)
32
+ mini_portile2 (2.3.0)
33
+ minitest (5.11.3)
34
+ nokogiri (1.8.2)
35
+ mini_portile2 (~> 2.3.0)
36
+ rails-dom-testing (2.0.3)
37
+ activesupport (>= 4.2.0)
38
+ nokogiri (>= 1.6)
39
+ rails-html-sanitizer (1.0.3)
40
+ loofah (~> 2.0)
41
+ rake (10.5.0)
42
+ rspec (3.7.0)
43
+ rspec-core (~> 3.7.0)
44
+ rspec-expectations (~> 3.7.0)
45
+ rspec-mocks (~> 3.7.0)
46
+ rspec-core (3.7.1)
47
+ rspec-support (~> 3.7.0)
48
+ rspec-expectations (3.7.0)
49
+ diff-lcs (>= 1.2.0, < 2.0)
50
+ rspec-support (~> 3.7.0)
51
+ rspec-mocks (3.7.0)
52
+ diff-lcs (>= 1.2.0, < 2.0)
53
+ rspec-support (~> 3.7.0)
54
+ rspec-support (3.7.1)
55
+ thread_safe (0.3.6)
56
+ tzinfo (1.2.5)
57
+ thread_safe (~> 0.1)
58
+
59
+ PLATFORMS
60
+ ruby
61
+
62
+ DEPENDENCIES
63
+ bundler (~> 1.16.a)
64
+ rails_vue_helpers!
65
+ rake (~> 10.0)
66
+ rspec (~> 3.6)
67
+
68
+ BUNDLED WITH
69
+ 1.16.1
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2018 Kristaps Kulikovskis
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,85 @@
1
+ # Rails Vue Helpers
2
+
3
+ This small helper gem allows you to add Vue components to your Rails views with a clean syntax.
4
+
5
+ Instead of writing
6
+ ```ruby
7
+ <some-component v-on:click='doThis' v-bind:vueParam="<%= @some_instance.to_json %>" />
8
+ ````
9
+ you can write
10
+
11
+ ```ruby
12
+ <%= vue_component('someComponent', events: { click: 'doThis'}, binded: { vue_param: @some_instance}) %>
13
+ ```
14
+
15
+ This gem conveniently calls `to_json` on objects, as well as handles cases where parameters include single or double quotes, without screwing up HTML rendering.
16
+
17
+ All you need to do this wrap everything in a Vue initialized container, and you're good to go.
18
+
19
+ ## Installation
20
+
21
+ ```ruby
22
+ gem 'rails_vue_helpers'
23
+ ```
24
+
25
+ ## Usage
26
+
27
+ `vue_component('componentName', **args, &block)`
28
+
29
+ All arguments, except special keys: `binded:`, `events:`, `raw:` are translated in regular camelCased Vue props
30
+
31
+
32
+ ### Events
33
+
34
+ ```ruby
35
+ <%= vue_component('someComponent', events: { click: 'doThis'} ) %>
36
+ ```
37
+ will result in
38
+
39
+ ```ruby
40
+ <some-component v-on:click='doThis'></some-component>
41
+ ```
42
+
43
+ ### Binded parameters
44
+
45
+ ```ruby
46
+ <%= vue_component('someComponent', binded: { some_array: ['a', 'b'], some_boolean: true } ) %>
47
+ ```
48
+ will result in
49
+
50
+ ```ruby
51
+ <some-component v-bind:someArray="['a', 'b']", v-bind:someBoolean="true"></some-component>
52
+ ```
53
+
54
+ ### Directives or custom attributes
55
+
56
+ ```ruby
57
+ <%= vue_component('someComponent', raw: 'v-something v-something-else') %>
58
+ ```
59
+ will result in
60
+
61
+ ```ruby
62
+ <some-component v-something v-something-else></some-component>
63
+ ```
64
+
65
+ ### Wrapper
66
+
67
+ ```ruby
68
+ <%= vue_component('someWrapperComponent') do %>
69
+ <div>Everything else you need in rails view</div>
70
+ <%= vue_component('someInnerComponent') %>
71
+ <% end %>
72
+ ```
73
+ will result in
74
+
75
+ ```ruby
76
+ <some-wrapper-component>
77
+ <div>Everything else you need in rails view</div>
78
+ <some-inner-component></some-inner-component>
79
+ </some-component>
80
+ ```
81
+
82
+
83
+ ## License
84
+
85
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
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,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,10 @@
1
+ require "rails_vue_helpers/version"
2
+ require 'active_support'
3
+ require 'active_support/core_ext/object/blank'
4
+ require 'action_view'
5
+ require 'rails_vue_helpers/vue_component_builder'
6
+ require "rails_vue_helpers/vue_helper"
7
+
8
+ ActiveSupport.on_load(:action_view) do
9
+ include RailsVueHelpers::VueHelper
10
+ end
@@ -0,0 +1,3 @@
1
+ module RailsVueHelpers
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,70 @@
1
+ class RailsVueHelpers::VueComponentBuilder
2
+ delegate :capture, :content_tag, to: :@template
3
+ def initialize(template, component_name, **props)
4
+ @component_name = component_name
5
+ @props = props
6
+ @template = template
7
+ @raw = @props[:raw]
8
+ end
9
+
10
+ def to_html(&block)
11
+ if block_given?
12
+ ActiveSupport::SafeBuffer.new("<#{sanitized_component_name} #{attributes} #{@raw}>#{capture(&block)}</#{sanitized_component_name}>")
13
+ else
14
+ ActiveSupport::SafeBuffer.new("<#{sanitized_component_name} #{attributes} #{@raw}></#{sanitized_component_name}>")
15
+ end
16
+ end
17
+
18
+ def sanitized_component_name
19
+ ActiveSupport::Inflector.underscore(@component_name.to_s).tr('_', '-')
20
+ end
21
+
22
+ private
23
+
24
+ def attributes
25
+ [binded_props, event_props, regular_props].flatten.join(' ')
26
+ end
27
+
28
+ def binded_props
29
+ binded_props = @props[:binded] || {}
30
+ binded_props.map { |key, value| transpile_binded_prop(key, value) }
31
+ end
32
+
33
+ def event_props
34
+ event_props = @props[:events] || {}
35
+ event_props.map { |key, value| transpile_event_prop(key, value) }
36
+ end
37
+
38
+ def regular_props
39
+ regular_props = @props.reject { |key, value| [:events, :binded, :raw].include?(key) }
40
+ regular_props.map { |key, value| transpile_regular_prop(key, value) }
41
+ end
42
+
43
+ def transpile_regular_prop(key, value)
44
+ normalized_key = key.to_s.underscore.tr('_', '-')
45
+ normalized_value = value
46
+
47
+ if value.is_a?(Array)
48
+ normalized_value = value.to_s.tr('"', '\'')
49
+ elsif value =~ /"/
50
+ normalized_value = value.tr('"', '\'')
51
+ end
52
+ "#{normalized_key}=\"#{normalized_value}\" "
53
+ end
54
+
55
+ def transpile_binded_prop(key, value)
56
+ normalized_key = ActiveSupport::Inflector.underscore(key.to_s).tr('_', '-')
57
+ normalized_value = value
58
+ unless value.is_a?(String)
59
+ # if there are some single quotes in the text, make them in ASCII
60
+ # so HTML doesn't brake
61
+ normalized_value = value.to_json.gsub("'", "&#39")
62
+ end
63
+ "v-bind:#{normalized_key}='#{normalized_value}'"
64
+ end
65
+
66
+ def transpile_event_prop(key, value)
67
+ normalized_key = key.to_s.underscore.tr('_', '-')
68
+ "v-on:#{normalized_key}='#{value}'"
69
+ end
70
+ end
@@ -0,0 +1,5 @@
1
+ module RailsVueHelpers::VueHelper
2
+ def vue_component(component_name, **props, &block)
3
+ RailsVueHelpers::VueComponentBuilder.new(self, component_name, **props).to_html(&block)
4
+ end
5
+ end
@@ -0,0 +1,31 @@
1
+
2
+ lib = File.expand_path("../lib", __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require "rails_vue_helpers/version"
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "rails_vue_helpers"
8
+ spec.version = RailsVueHelpers::VERSION
9
+ spec.authors = ["Kristaps Kulikovskis"]
10
+ spec.email = ["kristaps.kulikovskis@gmail.lv"]
11
+
12
+ spec.summary = %q{ActionView helper methods for injecting Vue.js components into your Rails views}
13
+ spec.description = %q{ActionView helper methods for injecting Vue.js components into your Rails views}
14
+ spec.homepage = "https://github.com/LeKristapino/rails_vue_helpers"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+
21
+ # spec.bindir = "exe"
22
+ # spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
23
+ spec.require_paths = ["lib"]
24
+
25
+ spec.add_dependency 'activesupport', ['>= 4.1', '< 6.0']
26
+ spec.add_dependency 'actionview', ['>= 4.1', '< 6.0']
27
+
28
+ spec.add_development_dependency "bundler", "~> 1.16.a"
29
+ spec.add_development_dependency "rake", "~> 10.0"
30
+ spec.add_development_dependency "rspec", "~> 3.6"
31
+ end
metadata ADDED
@@ -0,0 +1,144 @@
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
+ - Kristaps Kulikovskis
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2018-04-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: activesupport
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '4.1'
20
+ - - "<"
21
+ - !ruby/object:Gem::Version
22
+ version: '6.0'
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ version: '4.1'
30
+ - - "<"
31
+ - !ruby/object:Gem::Version
32
+ version: '6.0'
33
+ - !ruby/object:Gem::Dependency
34
+ name: actionview
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ version: '4.1'
40
+ - - "<"
41
+ - !ruby/object:Gem::Version
42
+ version: '6.0'
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '4.1'
50
+ - - "<"
51
+ - !ruby/object:Gem::Version
52
+ version: '6.0'
53
+ - !ruby/object:Gem::Dependency
54
+ name: bundler
55
+ requirement: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - "~>"
58
+ - !ruby/object:Gem::Version
59
+ version: 1.16.a
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - "~>"
65
+ - !ruby/object:Gem::Version
66
+ version: 1.16.a
67
+ - !ruby/object:Gem::Dependency
68
+ name: rake
69
+ requirement: !ruby/object:Gem::Requirement
70
+ requirements:
71
+ - - "~>"
72
+ - !ruby/object:Gem::Version
73
+ version: '10.0'
74
+ type: :development
75
+ prerelease: false
76
+ version_requirements: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - "~>"
79
+ - !ruby/object:Gem::Version
80
+ version: '10.0'
81
+ - !ruby/object:Gem::Dependency
82
+ name: rspec
83
+ requirement: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - "~>"
86
+ - !ruby/object:Gem::Version
87
+ version: '3.6'
88
+ type: :development
89
+ prerelease: false
90
+ version_requirements: !ruby/object:Gem::Requirement
91
+ requirements:
92
+ - - "~>"
93
+ - !ruby/object:Gem::Version
94
+ version: '3.6'
95
+ description: ActionView helper methods for injecting Vue.js components into your Rails
96
+ views
97
+ email:
98
+ - kristaps.kulikovskis@gmail.lv
99
+ executables: []
100
+ extensions: []
101
+ extra_rdoc_files: []
102
+ files:
103
+ - ".gitignore"
104
+ - ".rspec"
105
+ - ".travis.yml"
106
+ - CODE_OF_CONDUCT.md
107
+ - Gemfile
108
+ - Gemfile.lock
109
+ - LICENSE.txt
110
+ - README.md
111
+ - Rakefile
112
+ - bin/console
113
+ - bin/setup
114
+ - lib/rails_vue_helpers.rb
115
+ - lib/rails_vue_helpers/version.rb
116
+ - lib/rails_vue_helpers/vue_component_builder.rb
117
+ - lib/rails_vue_helpers/vue_helper.rb
118
+ - rails_vue_helpers.gemspec
119
+ homepage: https://github.com/LeKristapino/rails_vue_helpers
120
+ licenses:
121
+ - MIT
122
+ metadata: {}
123
+ post_install_message:
124
+ rdoc_options: []
125
+ require_paths:
126
+ - lib
127
+ required_ruby_version: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ required_rubygems_version: !ruby/object:Gem::Requirement
133
+ requirements:
134
+ - - ">="
135
+ - !ruby/object:Gem::Version
136
+ version: '0'
137
+ requirements: []
138
+ rubyforge_project:
139
+ rubygems_version: 2.6.11
140
+ signing_key:
141
+ specification_version: 4
142
+ summary: ActionView helper methods for injecting Vue.js components into your Rails
143
+ views
144
+ test_files: []