modulizer 0.1.0 → 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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1194028d7534c59244b0d789c2e4f94ceb50d190
4
- data.tar.gz: 4e2b714d56290c0a6e6767c1715e23beb586362f
3
+ metadata.gz: 5d021a23274e7d5ad73e2503e527c4645c1e5503
4
+ data.tar.gz: c3abe7234e1843404398649c1d4dacd2f24b4983
5
5
  SHA512:
6
- metadata.gz: fed78158ea779b8c143064c0cffe478e8e2cfe396632a08a2e1454615fa41d3177be8bf14210a4ca908b4249f1d939d7b232201899de2d52b66c37dfe4ecc59b
7
- data.tar.gz: 50bc1a9495700a30e2284f4111ff3bd6007d3af143b7ebaaf7bb215f9f994fc92ca54afb4827a65d6de625d4f4c6e38f21e111f96a942beb0fee7b584916f51e
6
+ metadata.gz: 32703f525fd8f845767c4eeb739515866d64b1ceb72f4a5c9b65352b2f689fdfb4b2662a13ea4a4e64cf4f2e99d395116053a48b7f0bb99f91d1e4b576ee9428
7
+ data.tar.gz: 580d6b677b6a69a83999aa1dd7aebaed0291933a3ce7580ebb855349ec38c31219c4c1b4413c07ae476fcedb90676ebd17230d6d433a136bddffeeeb7944e7ae
data/.gitignore CHANGED
@@ -8,4 +8,4 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  .DS_store
11
- .gem
11
+ *.gem
@@ -9,12 +9,23 @@ require 'optparse'
9
9
 
10
10
  options = {}
11
11
  OptionParser.new do |opts|
12
- opts.banner = "Usage: modulizer.rb [options]"
12
+ opts.banner = """
13
+ Modulizer: a ruby gem that modulize the web pages
14
+ author: dave wu (eyaswoo@163.com)
15
+ Sept. 2016 MIT
13
16
 
14
- opts.on("-e", "--entry ENTRY_FILE", "input file") do |e|
17
+ Usage:
18
+ $> modulizer [options]
19
+ """
20
+
21
+ opts.on("-e", "--entry ENTRY_FILE", "input file, normally html") do |e|
15
22
  options[:input] = e
16
23
  end
17
24
 
25
+ opts.on("-o", "--output OUTPUT_FILE", "output file, normally js. if not provided, output to stdout") do |o|
26
+ options[:output] = o
27
+ end
28
+
18
29
  opts.on("-h", "--help", "Prints this help") do
19
30
  puts opts
20
31
  exit
@@ -22,6 +33,12 @@ OptionParser.new do |opts|
22
33
  end.parse!
23
34
 
24
35
  mod_file = options[:input]
25
- raise "invalid input #{mod_file}" unless mod_file
36
+ raise "valid input module file is required" unless mod_file
37
+
38
+ result = Modulizer::Dummy.compile mod_file
26
39
 
27
- Modulizer::Dummy.compile mod_file
40
+ if options[:output].nil?
41
+ puts result
42
+ else
43
+ File.write(options[:output], result)
44
+ end
@@ -1,4 +1,5 @@
1
1
  require "modulizer/version"
2
+ require "modulizer/stylebuilder"
2
3
 
3
4
  module Modulizer
4
5
  class Dummy
@@ -15,25 +16,25 @@ module Modulizer
15
16
  template_mode = read_attributes template[1]
16
17
 
17
18
  script_content = escape_js_variable_string script[2]
18
- style_content = escape_js_variable_string style[2]
19
+ style_content = escape_js_variable_string(StyleBuilder.build(mod_name, style[2], style_mode))
19
20
  template_content = escape_js_variable_string template[2]
20
21
 
21
- puts """/* generated js file for module:#{mod_name} */
22
- (function(window,$){
23
- var script =
24
- '<script>#{script_content}</script>';
22
+ """/* generated js file for module:#{mod_name} */
23
+ (function(window,$){
24
+ var script =
25
+ '<script>#{script_content}</script>';
25
26
 
26
- var template =
27
- '#{template_content}';
27
+ var template =
28
+ '#{template_content}';
28
29
 
29
- var style =
30
- '<style>#{style_content}</style>';
30
+ var style =
31
+ '<style>#{style_content}</style>';
31
32
 
32
- $(function(){
33
- $('div##{mod_name}').html(style + template + script);
34
- });
35
- })(window, jQuery);
36
- """
33
+ $(function(){
34
+ $('div##{mod_name}').html(style + template + script);
35
+ });
36
+ })(window, jQuery);
37
+ """
37
38
  end
38
39
 
39
40
  private
@@ -0,0 +1,31 @@
1
+ module Modulizer
2
+ class StyleBuilder
3
+ def self.build(mod_name, raw_content, mode = {})
4
+ result = "\n"
5
+ style_items = raw_content.scan /(.*?){(.*?)}/m
6
+
7
+ style_items.each do |s|
8
+ selectors = s[0].strip.delete("\n")
9
+ principles = s[1].strip.delete("\n")
10
+
11
+ if mode["scoped"] == true
12
+ new_selectors = ""
13
+ selectors.split(',').each do |s|
14
+ new_selectors += "div##{mod_name} #{s.strip}, "
15
+ end
16
+ new_selectors.strip!
17
+ new_selectors = new_selectors[0...-1] if new_selectors[-1] == ','
18
+ selectors = new_selectors
19
+ end
20
+
21
+ new_principles = ""
22
+ principles.split(";").each do |p|
23
+ new_principles += "#{p.strip}; "
24
+ end
25
+
26
+ result += "#{selectors} {#{new_principles.strip}}\n"
27
+ end
28
+ result
29
+ end
30
+ end
31
+ end
@@ -1,3 +1,3 @@
1
1
  module Modulizer
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -8,8 +8,9 @@ Gem::Specification.new do |spec|
8
8
  spec.version = Modulizer::VERSION
9
9
  spec.authors = ["dave"]
10
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"
11
+ spec.summary = "a ruby gem that modulize the web pages"
12
+ spec.description = "One easy way to develop web applications with isolated and reusable web page modules." +
13
+ "For more detailed information, please refer to https://github.com/straightdave/modulizer"
13
14
  spec.homepage = "https://github.com/straightdave/modulizer"
14
15
  spec.license = "MIT"
15
16
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: modulizer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dave
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-09-06 00:00:00.000000000 Z
11
+ date: 2016-09-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -52,8 +52,8 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '3.0'
55
- description: one easy way to develop web applications with isolated and reusable web
56
- page modules
55
+ description: One easy way to develop web applications with isolated and reusable web
56
+ page modules.For more detailed information, please refer to https://github.com/straightdave/modulizer
57
57
  email:
58
58
  - eyaswoo@163.com
59
59
  executables:
@@ -73,6 +73,7 @@ files:
73
73
  - bin/setup
74
74
  - exe/modulizer
75
75
  - lib/modulizer.rb
76
+ - lib/modulizer/stylebuilder.rb
76
77
  - lib/modulizer/version.rb
77
78
  - modulizer.gemspec
78
79
  homepage: https://github.com/straightdave/modulizer
@@ -98,5 +99,5 @@ rubyforge_project:
98
99
  rubygems_version: 2.6.3
99
100
  signing_key:
100
101
  specification_version: 4
101
- summary: compiler for web page modules
102
+ summary: a ruby gem that modulize the web pages
102
103
  test_files: []