rails-vue-loader 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.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: ab53f9869105f9cf3949edc2a655e65081bad0e8
4
+ data.tar.gz: b5a39ea6739ee7e3baec5fdf780954f861aa3611
5
+ SHA512:
6
+ metadata.gz: 79b9d87e0683e01a7cba63628d9d570db82d33f1978f9deaab26f0cdddf9bd4570499178f58ba75783ed343047f3bad5156df5a89fd34297d245289152b559f3
7
+ data.tar.gz: bc459c8ffe151f0001d8a0528dab65847bf2eca8e4005224104223ef4657365c2c1f4163792a9256e8e785efce4b33ce8c944d78d7d1d0e4799d6eaf17c3ba0d
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2016 Kikyous
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.
@@ -0,0 +1,90 @@
1
+ # sprockets-vue
2
+
3
+ [![Gem](https://img.shields.io/gem/v/sprockets-vue.svg)](https://rubygems.org/gems/sprockets-vue)
4
+ [![Gem](https://img.shields.io/gem/dt/sprockets-vue.svg)](https://rubygems.org/gems/sprockets-vue)
5
+
6
+ A [Sprockets](https://github.com/rails/sprockets) transformer that converts .vue file into js object.
7
+
8
+
9
+ # heads up!
10
+
11
+ version 0.1.0 has incompatible changes, attempting to make the syntax
12
+ work more similarly to Webpack/vue-loader.
13
+
14
+ Specifically:
15
+
16
+ - You should assign `module.exports` variable to make it work! (not vm)
17
+ - You should use `VComponents` instead of `VCompents`
18
+ - Now supports normal javascript (as well as coffeescript)
19
+
20
+ # feature
21
+
22
+ following tag is supported in .vue file
23
+ * script (coffeescript and js)
24
+ * template (currently html only)
25
+ * style (scss, sass and css)
26
+
27
+ # install
28
+ add `gem 'sprockets-vue'` to Gemfile, and run bundle, currently works with sprockets 3.
29
+
30
+ # example
31
+ * index.vue
32
+ ```vue
33
+ //= require components/card
34
+ <script lang="coffee">
35
+ module.exports = {
36
+ data: ->
37
+ search: ''
38
+ members: []
39
+ components:
40
+ card: VComponents['components/card']
41
+ methods:
42
+ clear: ->
43
+ this.search = ''
44
+ }
45
+ </script>
46
+
47
+ <template>
48
+ <div class="container">
49
+ <div class='search icon-input'>
50
+ <span class="search-icon glyphicon glyphicon-search"></span>
51
+ <input class="form-control" type="text" v-model='search'>
52
+ <span @click='clear' class="clear-icon glyphicon glyphicon-remove"></span>
53
+ </div>
54
+ <card v-for="m in members" :m='m'></card>
55
+ </div>
56
+ </template>
57
+
58
+ <style lang="scss">
59
+ .search{
60
+ .icon-input{
61
+ width: 100%;
62
+ }
63
+ }
64
+ </style>
65
+ ```
66
+
67
+ * application.coffee
68
+
69
+ ```coffee
70
+ #= require index
71
+
72
+ new Vue(
73
+ el: '#search',
74
+ components: {
75
+ 'index': VComponents.index
76
+ }
77
+ )
78
+ ```
79
+
80
+ * application.scss
81
+ ```scss
82
+ //=require index
83
+ ```
84
+
85
+ > you can include .vue file in css file, it's style block will be automatic processed.
86
+ you can also use `require_tree` to include all .vue file.😘
87
+ `scoped` will not be supported.
88
+
89
+ # advanced
90
+ * [multi file component](https://github.com/kikyous/sprockets-vue/wiki/multi-file-component)
@@ -0,0 +1,14 @@
1
+ require 'sprockets'
2
+ require 'sprockets/vue/version'
3
+ require 'sprockets/vue/utils'
4
+ require 'sprockets/vue/script'
5
+ require 'sprockets/vue/style'
6
+ module Sprockets
7
+ if respond_to?(:register_transformer)
8
+ register_mime_type 'text/vue', extensions: ['.vue'], charset: :unicode
9
+ register_transformer 'text/vue', 'application/javascript', Vue::Script
10
+ register_transformer 'text/vue', 'text/css', Vue::Style
11
+
12
+ register_processor 'text/vue', Sprockets::DirectiveProcessor
13
+ end
14
+ end
@@ -0,0 +1,57 @@
1
+ require 'active_support/concern'
2
+ require "action_view"
3
+ module Sprockets::Vue
4
+ class Script
5
+ class << self
6
+ include ActionView::Helpers::JavaScriptHelper
7
+
8
+ SCRIPT_REGEX = Utils.node_regex('script')
9
+ TEMPLATE_REGEX = Utils.node_regex('template')
10
+ SCRIPT_COMPILES = {
11
+ 'coffee' => ->(s, input){
12
+ CoffeeScript.compile(s, sourceMap: true, sourceFiles: [input[:source_path]], no_wrap: true)
13
+ },
14
+ 'es6' => ->(s, input){
15
+ Babel::Transpiler.transform(data, {}) #TODO
16
+ },
17
+ nil => ->(s,input){ { 'js' => s } }
18
+ }
19
+ def call(input)
20
+ data = input[:data]
21
+ name = input[:name]
22
+ input[:cache].fetch([cache_key, input[:source_path], data]) do
23
+ script = SCRIPT_REGEX.match(data)
24
+ template = TEMPLATE_REGEX.match(data)
25
+ output = []
26
+ map = nil
27
+ if script
28
+ result = SCRIPT_COMPILES[script[:lang]].call(script[:content], input)
29
+
30
+ map = result['sourceMap']
31
+
32
+ output << "'object' != typeof VComponents && (this.VComponents = {});
33
+ var module = { exports: null };
34
+ #{result['js']}; VComponents['#{name}'] = module.exports;"
35
+ end
36
+
37
+ if template
38
+ output << "VComponents['#{name.sub(/\.tpl$/, "")}'].template = '#{j template[:content]}';"
39
+ end
40
+
41
+ { data: "#{warp(output.join)}", map: map }
42
+ end
43
+ end
44
+
45
+ def warp(s)
46
+ "(function(){#{s}}).call(this);"
47
+ end
48
+
49
+ def cache_key
50
+ [
51
+ self.name,
52
+ VERSION,
53
+ ].freeze
54
+ end
55
+ end
56
+ end
57
+ end
@@ -0,0 +1,31 @@
1
+ module Sprockets::Vue
2
+ class Style
3
+ class << self
4
+ STYLE_REGEX = Utils.node_regex('style')
5
+ STYLE_COMPILES = {
6
+ 'scss' => Sprockets::ScssProcessor,
7
+ 'sass' => Sprockets::SassProcessor,
8
+ nil => ->(i){i[:data]}
9
+ }
10
+ def call(input)
11
+ data = input[:data]
12
+ input[:cache].fetch([cache_key, input[:filename], data]) do
13
+ style = STYLE_REGEX.match(data)
14
+ if style
15
+ input[:data] = style[:content]
16
+ STYLE_COMPILES[style[:lang]].call(input)
17
+ else
18
+ ''
19
+ end
20
+ end
21
+ end
22
+
23
+ def cache_key
24
+ [
25
+ self.name,
26
+ VERSION,
27
+ ].freeze
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,13 @@
1
+ module Sprockets::Vue::Utils
2
+ class << self
3
+ def node_regex(tag)
4
+ %r(
5
+ \<#{tag}
6
+ (\s+lang=["'](?<lang>\w+)["'])?
7
+ \>
8
+ (?<content>.+)
9
+ \<\/#{tag}\>
10
+ )mx
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,5 @@
1
+ module Sprockets
2
+ module Vue
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
metadata ADDED
@@ -0,0 +1,177 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rails-vue-loader
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - kikyous
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2017-08-24 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: sprockets
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: 3.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: 3.0.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionview
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
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: activesupport
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :runtime
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: rake
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: minitest
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: execjs
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
+ - !ruby/object:Gem::Dependency
98
+ name: pry
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: sass
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: coffee-script
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ description: " A Sprockets transformer that converts .vue file into
140
+ js object.\n"
141
+ email: kikyous@163.com
142
+ executables: []
143
+ extensions: []
144
+ extra_rdoc_files: []
145
+ files:
146
+ - MIT-LICENSE
147
+ - README.md
148
+ - lib/sprockets/vue.rb
149
+ - lib/sprockets/vue/script.rb
150
+ - lib/sprockets/vue/style.rb
151
+ - lib/sprockets/vue/utils.rb
152
+ - lib/sprockets/vue/version.rb
153
+ homepage: https://github.com/kikyous/rails-vue-loader
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - ">="
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - ">="
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.5.1
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Sprockets Vue transformer
177
+ test_files: []