modulizer 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 +11 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +49 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +89 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/setup +8 -0
- data/exe/modulizer +27 -0
- data/lib/modulizer/version.rb +3 -0
- data/lib/modulizer.rb +62 -0
- data/modulizer.gemspec +24 -0
- metadata +102 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 1194028d7534c59244b0d789c2e4f94ceb50d190
|
4
|
+
data.tar.gz: 4e2b714d56290c0a6e6767c1715e23beb586362f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: fed78158ea779b8c143064c0cffe478e8e2cfe396632a08a2e1454615fa41d3177be8bf14210a4ca908b4249f1d939d7b232201899de2d52b66c37dfe4ecc59b
|
7
|
+
data.tar.gz: 50bc1a9495700a30e2284f4111ff3bd6007d3af143b7ebaaf7bb215f9f994fc92ca54afb4827a65d6de625d4f4c6e38f21e111f96a942beb0fee7b584916f51e
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
# Contributor Code of Conduct
|
2
|
+
|
3
|
+
As contributors and maintainers of this project, and in the interest of
|
4
|
+
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
+
contribute through reporting issues, posting feature requests, updating
|
6
|
+
documentation, submitting pull requests or patches, and other activities.
|
7
|
+
|
8
|
+
We are committed to making participation in this project a harassment-free
|
9
|
+
experience for everyone, regardless of level of experience, gender, gender
|
10
|
+
identity and expression, sexual orientation, disability, personal appearance,
|
11
|
+
body size, race, ethnicity, age, religion, or nationality.
|
12
|
+
|
13
|
+
Examples of unacceptable behavior by participants include:
|
14
|
+
|
15
|
+
* The use of sexualized language or imagery
|
16
|
+
* Personal attacks
|
17
|
+
* Trolling or insulting/derogatory comments
|
18
|
+
* Public or private harassment
|
19
|
+
* Publishing other's private information, such as physical or electronic
|
20
|
+
addresses, without explicit permission
|
21
|
+
* Other unethical or unprofessional conduct
|
22
|
+
|
23
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
24
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
25
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
26
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
27
|
+
threatening, offensive, or harmful.
|
28
|
+
|
29
|
+
By adopting this Code of Conduct, project maintainers commit themselves to
|
30
|
+
fairly and consistently applying these principles to every aspect of managing
|
31
|
+
this project. Project maintainers who do not follow or enforce the Code of
|
32
|
+
Conduct may be permanently removed from the project team.
|
33
|
+
|
34
|
+
This code of conduct applies both within project spaces and in public spaces
|
35
|
+
when an individual is representing the project or its community.
|
36
|
+
|
37
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
+
reported by contacting a project maintainer at eyaswoo@gmail.com. All
|
39
|
+
complaints will be reviewed and investigated and will result in a response that
|
40
|
+
is deemed necessary and appropriate to the circumstances. Maintainers are
|
41
|
+
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
+
incident.
|
43
|
+
|
44
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
+
version 1.3.0, available at
|
46
|
+
[http://contributor-covenant.org/version/1/3/0/][version]
|
47
|
+
|
48
|
+
[homepage]: http://contributor-covenant.org
|
49
|
+
[version]: http://contributor-covenant.org/version/1/3/0/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 dave
|
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,89 @@
|
|
1
|
+
# modulizer
|
2
|
+
a ruby gem that modulize the web pages
|
3
|
+
|
4
|
+
## basic idea
|
5
|
+
while building web applications,
|
6
|
+
you may need to separate a complex web page into pieces which are more isolated,
|
7
|
+
independent, easy-to-maintain and, the most important, reusable.
|
8
|
+
similar to 'partial' components in many backend frameworks (eg. sinatra, rails).
|
9
|
+
further more, it'll be good if you can package all things together, like the html templates, styles and scripts.
|
10
|
+
|
11
|
+
this'll make it easy to develop a web site with complex pages.
|
12
|
+
|
13
|
+
## get started
|
14
|
+
assume you have a module file with the content:
|
15
|
+
```html
|
16
|
+
<!-- my_mod.html -->
|
17
|
+
<style scoped>
|
18
|
+
h2 {
|
19
|
+
color: red;
|
20
|
+
}
|
21
|
+
</style>
|
22
|
+
|
23
|
+
<template>
|
24
|
+
<h2>Hello, world!</h2>
|
25
|
+
</template>
|
26
|
+
|
27
|
+
<script>
|
28
|
+
$(function(){
|
29
|
+
$('h2').on('click', function () {
|
30
|
+
alert('haha');
|
31
|
+
});
|
32
|
+
});
|
33
|
+
</script>
|
34
|
+
```
|
35
|
+
|
36
|
+
then, use the gem to compile:
|
37
|
+
```
|
38
|
+
$> modulizer -e my_mod.html -o builds/my_mod.js
|
39
|
+
```
|
40
|
+
|
41
|
+
it will be compiled to a js file:
|
42
|
+
```javascript
|
43
|
+
/* auto-generated js for my-mod */
|
44
|
+
(function (window, $) {
|
45
|
+
var style =
|
46
|
+
'<style>\
|
47
|
+
div#my_mod h2 {\
|
48
|
+
color: red;\
|
49
|
+
}\
|
50
|
+
</style>';
|
51
|
+
|
52
|
+
var template =
|
53
|
+
'<h2>Hello, world</h2>';
|
54
|
+
|
55
|
+
var script =
|
56
|
+
'<script>\
|
57
|
+
(function(window, $) {\
|
58
|
+
$(function(){\
|
59
|
+
$(\'div#my_mod h2\').on(\'click\', function () {\
|
60
|
+
alert(\'haha\');\
|
61
|
+
});\
|
62
|
+
});\
|
63
|
+
})(window,jQuery);\
|
64
|
+
</script>';
|
65
|
+
|
66
|
+
$(function() {
|
67
|
+
$("div#my_mod").html(style + template + script);
|
68
|
+
});
|
69
|
+
})(window, jQuery);
|
70
|
+
```
|
71
|
+
|
72
|
+
at last, you load the module and use it in your html page:
|
73
|
+
```html
|
74
|
+
<!DOCTYPE html>
|
75
|
+
<html>
|
76
|
+
<meta charset="utf-8">
|
77
|
+
<title>The Title</title>
|
78
|
+
<body>
|
79
|
+
|
80
|
+
<div id="my-mod"></div>
|
81
|
+
|
82
|
+
<script src="js/jquery-3.1.0.min.js"></script>
|
83
|
+
<script src="modules/builds/my_mod.js"></script>
|
84
|
+
</body>
|
85
|
+
</html>
|
86
|
+
```
|
87
|
+
>You can compress the js files of modules
|
88
|
+
|
89
|
+
Voila!
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "modulizer"
|
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
|
data/bin/setup
ADDED
data/exe/modulizer
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Exit cleanly from an early interrupt
|
5
|
+
Signal.trap("INT") { exit 1 }
|
6
|
+
|
7
|
+
require "modulizer"
|
8
|
+
require 'optparse'
|
9
|
+
|
10
|
+
options = {}
|
11
|
+
OptionParser.new do |opts|
|
12
|
+
opts.banner = "Usage: modulizer.rb [options]"
|
13
|
+
|
14
|
+
opts.on("-e", "--entry ENTRY_FILE", "input file") do |e|
|
15
|
+
options[:input] = e
|
16
|
+
end
|
17
|
+
|
18
|
+
opts.on("-h", "--help", "Prints this help") do
|
19
|
+
puts opts
|
20
|
+
exit
|
21
|
+
end
|
22
|
+
end.parse!
|
23
|
+
|
24
|
+
mod_file = options[:input]
|
25
|
+
raise "invalid input #{mod_file}" unless mod_file
|
26
|
+
|
27
|
+
Modulizer::Dummy.compile mod_file
|
data/lib/modulizer.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require "modulizer/version"
|
2
|
+
|
3
|
+
module Modulizer
|
4
|
+
class Dummy
|
5
|
+
def self.compile(mod_file = "")
|
6
|
+
mod_name = mod_file[(mod_file.rindex('/')+1)...mod_file.rindex('.')]
|
7
|
+
content = File.read(mod_file)
|
8
|
+
|
9
|
+
script = content.match(/<script(.*?)>(.*)<\/script>/m)
|
10
|
+
style = content.match(/<style(.*?)>(.*)<\/style>/m)
|
11
|
+
template = content.match(/<template(.*?)>(.*)<\/template>/m)
|
12
|
+
|
13
|
+
script_mode = read_attributes script[1]
|
14
|
+
style_mode = read_attributes style[1]
|
15
|
+
template_mode = read_attributes template[1]
|
16
|
+
|
17
|
+
script_content = escape_js_variable_string script[2]
|
18
|
+
style_content = escape_js_variable_string style[2]
|
19
|
+
template_content = escape_js_variable_string template[2]
|
20
|
+
|
21
|
+
puts """/* generated js file for module:#{mod_name} */
|
22
|
+
(function(window,$){
|
23
|
+
var script =
|
24
|
+
'<script>#{script_content}</script>';
|
25
|
+
|
26
|
+
var template =
|
27
|
+
'#{template_content}';
|
28
|
+
|
29
|
+
var style =
|
30
|
+
'<style>#{style_content}</style>';
|
31
|
+
|
32
|
+
$(function(){
|
33
|
+
$('div##{mod_name}').html(style + template + script);
|
34
|
+
});
|
35
|
+
})(window, jQuery);
|
36
|
+
"""
|
37
|
+
end
|
38
|
+
|
39
|
+
private
|
40
|
+
def self.read_attributes(str = "")
|
41
|
+
m = {}
|
42
|
+
str.strip.split(' ').each do |item|
|
43
|
+
(k, v) = item.split('=')
|
44
|
+
m[k] =
|
45
|
+
if v.nil?
|
46
|
+
true
|
47
|
+
elsif (v[0] != '"' && v[-1] != '"') && (v[0] != "'" && v[-1] != "'")
|
48
|
+
raise "attributes should be in quotes"
|
49
|
+
else
|
50
|
+
v[1...-1]
|
51
|
+
end
|
52
|
+
end
|
53
|
+
m
|
54
|
+
end
|
55
|
+
|
56
|
+
def self.escape_js_variable_string(str = "")
|
57
|
+
str.gsub("\n", "\\\n")
|
58
|
+
.gsub("'", { "'" => "\\'" })
|
59
|
+
.gsub("\"", "\\\"")
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/modulizer.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'modulizer/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "modulizer"
|
8
|
+
spec.version = Modulizer::VERSION
|
9
|
+
spec.authors = ["dave"]
|
10
|
+
spec.email = ["eyaswoo@163.com"]
|
11
|
+
spec.summary = "compiler for web page modules"
|
12
|
+
spec.description = "one easy way to develop web applications with isolated and reusable web page modules"
|
13
|
+
spec.homepage = "https://github.com/straightdave/modulizer"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
17
|
+
spec.bindir = "exe"
|
18
|
+
spec.executables = ["modulizer"]
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.12"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
23
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: modulizer
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- dave
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-09-06 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.12'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.12'
|
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
|
+
description: one easy way to develop web applications with isolated and reusable web
|
56
|
+
page modules
|
57
|
+
email:
|
58
|
+
- eyaswoo@163.com
|
59
|
+
executables:
|
60
|
+
- modulizer
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files: []
|
63
|
+
files:
|
64
|
+
- ".gitignore"
|
65
|
+
- ".rspec"
|
66
|
+
- ".travis.yml"
|
67
|
+
- CODE_OF_CONDUCT.md
|
68
|
+
- Gemfile
|
69
|
+
- LICENSE.txt
|
70
|
+
- README.md
|
71
|
+
- Rakefile
|
72
|
+
- bin/console
|
73
|
+
- bin/setup
|
74
|
+
- exe/modulizer
|
75
|
+
- lib/modulizer.rb
|
76
|
+
- lib/modulizer/version.rb
|
77
|
+
- modulizer.gemspec
|
78
|
+
homepage: https://github.com/straightdave/modulizer
|
79
|
+
licenses:
|
80
|
+
- MIT
|
81
|
+
metadata: {}
|
82
|
+
post_install_message:
|
83
|
+
rdoc_options: []
|
84
|
+
require_paths:
|
85
|
+
- lib
|
86
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
87
|
+
requirements:
|
88
|
+
- - ">="
|
89
|
+
- !ruby/object:Gem::Version
|
90
|
+
version: '0'
|
91
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - ">="
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0'
|
96
|
+
requirements: []
|
97
|
+
rubyforge_project:
|
98
|
+
rubygems_version: 2.6.3
|
99
|
+
signing_key:
|
100
|
+
specification_version: 4
|
101
|
+
summary: compiler for web page modules
|
102
|
+
test_files: []
|