zfben_libjs 0.0.26 → 0.0.27

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.
data/README.md ADDED
@@ -0,0 +1,141 @@
1
+ # Lib.js
2
+
3
+ Lib.js = Frontend build tool + lazyload js tool
4
+
5
+ ## Getting Started
6
+
7
+ ```bash
8
+ gem install zfben_libjs
9
+
10
+ libjs new < project_name >
11
+ ```
12
+
13
+ ## Feature:
14
+
15
+ * lazyload css and js files (base on LazyLoad.js)
16
+ * minify css and js files (base on sass and uglifier)
17
+ * support sass, scss, compass and coffeescript files
18
+ * download remote files
19
+ * custom ruby script
20
+ * custom filetype
21
+ * before and after events
22
+ * custom routes
23
+
24
+ ## Support Filetype:
25
+
26
+ * .css - stylesheet
27
+
28
+ * .js - javascript
29
+
30
+ * .sass - sass
31
+
32
+ * .scss - scss
33
+
34
+ * .coffee - coffeescript
35
+
36
+ * .rb - ruby
37
+
38
+ * .??? - custom filetype
39
+
40
+ ## Javascript Example
41
+ ```javascript
42
+ // load jquery
43
+ lib.jquery(function(){
44
+ // something use jquery to do
45
+ });
46
+
47
+ // load jqueryui and not duplicate load jquery
48
+ lib.jqueryui(function(){
49
+ // something use jqueryui to do
50
+ });
51
+
52
+ // and you can load like
53
+ lib('jquery', function(){
54
+ // use jquery to do sth.
55
+ });
56
+
57
+ lib('jquery underscore', function(){
58
+ // use jquery and underscore to do sth.
59
+ });
60
+ ```
61
+ ## Rails Example
62
+ ```ruby
63
+ # Gemfile
64
+ gem 'zfben_libjs'
65
+ ```
66
+ ```erb
67
+ # layout.html.erb
68
+
69
+ <%= lib %>
70
+ # => <script src="/javascripts/lib.js?12345678"></script>
71
+
72
+ <%= lib :home %>
73
+ # => <script src="/javascripts/lib.js?12345678"></script><script>lib('home')</script>
74
+
75
+ <%= lib 'home.css' %>
76
+ # => <link rel="stylesheet" href="/stylesheets/home.css?12345678" /><script src="/javascripts/lib.js?12345678"></script>
77
+
78
+ <%= lib 'home.js' %>
79
+ # => <script src="/javascripts/home.js?12345678"></script><script src="/javascripts/lib.js?12345678"></script>
80
+ ```
81
+ ## Sinatra Example
82
+ ```ruby
83
+ helpers Zfben_libjs::Helpers
84
+ ```
85
+
86
+ ## Custom Filetype Example
87
+ ```yaml
88
+ # add support_source to config yaml file
89
+ support_source:
90
+ - mustache.rb
91
+ ```
92
+ ```ruby
93
+ # mustache.rb
94
+ class Zfben_libjs::Mustache < Zfben_libjs::Source
95
+ def after_initialize
96
+ @source = "this['#{File.basename(@filepath, '.mustache')}']=(data)->Mustache.to_html('''#{@source}''', data)"
97
+ end
98
+
99
+ def compile
100
+ Zfben_libjs::Coffee.new(:source => @source).compile
101
+ end
102
+
103
+ def to_js
104
+ compile
105
+ end
106
+
107
+ def minify
108
+ @minified = Zfben_libjs::Js.new(:source => @source).minify
109
+ end
110
+ end
111
+ ```
112
+
113
+ ## Routes
114
+ ```yaml
115
+ # add routes to config yaml file
116
+ routes:
117
+ "#Test_StringRoute": route_string
118
+ "/#Test_RegExpRoute/": route_regexp
119
+ ```
120
+
121
+ ## More Settings
122
+
123
+ See https://github.com/benz303/zfben_libjs/blob/master/test.yml
124
+
125
+ ## TODO
126
+
127
+ ### libjs
128
+ * Make lib() return as defferred object
129
+ * Add ready event
130
+
131
+ ### Compile
132
+ * Support Zfben_libjs::Libjs.new.build!(url)
133
+ * Support auto-compile when file changed
134
+ * Auto merge sass and scss to speed up compile
135
+ * Lazyload files to speed up load
136
+ * Add debug mode for javascript
137
+ * * use console.log(filepath)
138
+
139
+ ### Web Service
140
+ * Use sinatra as web server
141
+ * UI for control compile
data/Rakefile CHANGED
@@ -1,6 +1,5 @@
1
1
  require 'rubygems'
2
2
  require 'bundler/gem_tasks'
3
-
4
3
  require 'zfben_hanoi'
5
4
 
6
5
  namespace :test do
@@ -34,10 +34,19 @@ module Zfben_libjs::Helpers
34
34
  end
35
35
 
36
36
  def lib_js url
37
- return "<script src='/javascripts/#{url}#{Lib_version}'></script>"
37
+ return "<script src='#{asset_host}/javascripts/#{url}#{Lib_version}'></script>"
38
38
  end
39
39
 
40
40
  def lib_css url
41
- return "<link rel='stylesheet' href='/stylesheets/#{url}#{Lib_version}' />"
41
+ return "<link rel='stylesheet' href='#{asset_host}/stylesheets/#{url}#{Lib_version}' />"
42
+ end
43
+
44
+ def asset_host
45
+ if defined? Rails
46
+ if Rails.configuration.action_controller.has_key? :asset_host
47
+ return Rails.configuration.action_controller[:asset_host] + (request.port == 80 ? '' : (':' << request.port.to_s))
48
+ end
49
+ end
50
+ ''
42
51
  end
43
52
  end
@@ -36,13 +36,14 @@ class Zfben_libjs::Css < Zfben_libjs::Source
36
36
  end
37
37
 
38
38
  def change_images_url!
39
+ version = Time.now.strftime('?%s')
39
40
  @source = @source.partition_all(REGEXP_REMOTE_IMAGE).map{ |line|
40
41
  if REGEXP_REMOTE_IMAGE =~ line
41
42
  path = line.match(REGEXP_REMOTE_IMAGE)[1]
42
43
  filename = File.basename(path)
43
44
  path = File.join(@options['src/images'], filename)
44
45
  if File.exists?(path)
45
- url = @options['url/images'] + '/' + filename
46
+ url = @options['url/images'] + '/' + filename + version
46
47
  line = 'url("' << url << '")'
47
48
  end
48
49
  end
@@ -0,0 +1 @@
1
+ <h1>{{title}}</h1>
@@ -55,7 +55,9 @@ test('lib.libs', 6, function(){
55
55
  route_string: [ '/javascripts/route_string.js' ],
56
56
  route_regexp: [ '/javascripts/route_regexp.js' ],
57
57
  jquery: [ '/javascripts/jquery.js' ],
58
- jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
58
+ jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ],
59
+ mustache: [ '/javascripts/mustache.js' ],
60
+ custom_filetype: [ '/javascripts/mustache.js', '/javascripts/custom_filetype.js' ]
59
61
  }, 'lib.libs is ok');
60
62
 
61
63
  equal(typeof lib.lazyload, 'function', 'lib.lazyload is a function');
@@ -72,6 +74,8 @@ test('lib.libs', 6, function(){
72
74
  route_regexp: [ '/javascripts/route_regexp.js' ],
73
75
  jquery: [ '/javascripts/jquery.js' ],
74
76
  jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ],
77
+ mustache: [ '/javascripts/mustache.js' ],
78
+ custom_filetype: [ '/javascripts/mustache.js', '/javascripts/custom_filetype.js' ],
75
79
  test: 'test'
76
80
  }, "lib.libs({test: 'test'}) has been added");
77
81
 
@@ -88,7 +92,9 @@ test('lib.libs', 6, function(){
88
92
  route_string: [ '/javascripts/route_string.js' ],
89
93
  route_regexp: [ '/javascripts/route_regexp.js' ],
90
94
  jquery: [ '/javascripts/jquery.js' ],
91
- jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ]
95
+ jqueryui: [ '/javascripts/jquery.js', '/stylesheets/jqueryui.css', '/javascripts/jqueryui.js' ],
96
+ mustache: [ '/javascripts/mustache.js' ],
97
+ custom_filetype: [ '/javascripts/mustache.js', '/javascripts/custom_filetype.js' ]
92
98
  }, "lib.libs({test: null}) has been deleted");
93
99
 
94
100
  equal(typeof lib.test, 'undefined', 'lib.test is undefined');
@@ -157,3 +163,12 @@ asyncTest('RegExp route', 1, function(){
157
163
  start();
158
164
  }, 1000);
159
165
  });
166
+
167
+ module('Custom Filetype');
168
+
169
+ asyncTest('mustache', 1, function(){
170
+ lib('custom_filetype', function(){
171
+ equal(custom_filetype({title: 'Hello'}), '<h1>Hello</h1>', 'Mustache is ok');
172
+ start();
173
+ });
174
+ });
data/test/mustache.rb ADDED
@@ -0,0 +1,17 @@
1
+ class Zfben_libjs::Mustache < Zfben_libjs::Source
2
+ def after_initialize
3
+ @source = "this['#{File.basename(@filepath, '.mustache')}']=(data)->Mustache.to_html('''#{@source}''', data)"
4
+ end
5
+
6
+ def compile
7
+ Zfben_libjs::Coffee.new(:source => @source).compile
8
+ end
9
+
10
+ def to_js
11
+ compile
12
+ end
13
+
14
+ def minify
15
+ @minified = Zfben_libjs::Js.new(:source => @source).minify
16
+ end
17
+ end
data/test.yml CHANGED
@@ -4,6 +4,10 @@ config:
4
4
  download: false # if file isn't exists, it will be downloaded always
5
5
  changeImageUrl: true # change image urls in css
6
6
 
7
+ # Custom Filetypes
8
+ support_source:
9
+ - test/mustache.rb
10
+
7
11
  # Files to be download and writen in lib.js
8
12
  libs:
9
13
  support_filetype: test/support_filetype/*
@@ -23,6 +27,11 @@ libs:
23
27
  - https://ajax.googleapis.com/ajax/libs/jqueryui/1/jquery-ui.js
24
28
  - https://raw.github.com/jquery/jquery-ui/master/themes/base/jquery.ui.all.css
25
29
 
30
+ mustache: https://raw.github.com/janl/mustache.js/master/mustache.js
31
+ custom_filetype:
32
+ - mustache
33
+ - test/custom_filetype.mustache
34
+
26
35
  routes:
27
36
  "#Test_StringRoute": route_string
28
37
  "/#Test_RegExpRoute/": route_regexp
data/zfben_libjs.gemspec CHANGED
@@ -3,7 +3,7 @@ $:.push File.expand_path("../lib", __FILE__)
3
3
 
4
4
  Gem::Specification.new do |s|
5
5
  s.name = 'zfben_libjs'
6
- s.version = '0.0.26'
6
+ s.version = '0.0.27'
7
7
  s.authors = ["Ben"]
8
8
  s.email = ["ben@zfben.com"]
9
9
  s.homepage = "https://github.com/benz303/zfben_libjs"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: zfben_libjs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.26
4
+ version: 0.0.27
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-22 00:00:00.000000000Z
12
+ date: 2011-10-27 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rainbow
16
- requirement: &13459540 !ruby/object:Gem::Requirement
16
+ requirement: &21486400 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *13459540
24
+ version_requirements: *21486400
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: json
27
- requirement: &13455860 !ruby/object:Gem::Requirement
27
+ requirement: &21485940 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :runtime
34
34
  prerelease: false
35
- version_requirements: *13455860
35
+ version_requirements: *21485940
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: compass
38
- requirement: &13386320 !ruby/object:Gem::Requirement
38
+ requirement: &21485520 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :runtime
45
45
  prerelease: false
46
- version_requirements: *13386320
46
+ version_requirements: *21485520
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: coffee-script
49
- requirement: &13383200 !ruby/object:Gem::Requirement
49
+ requirement: &21485040 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,10 +54,10 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *13383200
57
+ version_requirements: *21485040
58
58
  - !ruby/object:Gem::Dependency
59
59
  name: uglifier
60
- requirement: &13381060 !ruby/object:Gem::Requirement
60
+ requirement: &21484620 !ruby/object:Gem::Requirement
61
61
  none: false
62
62
  requirements:
63
63
  - - ! '>='
@@ -65,10 +65,10 @@ dependencies:
65
65
  version: '0'
66
66
  type: :runtime
67
67
  prerelease: false
68
- version_requirements: *13381060
68
+ version_requirements: *21484620
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: activesupport
71
- requirement: &13348780 !ruby/object:Gem::Requirement
71
+ requirement: &21484020 !ruby/object:Gem::Requirement
72
72
  none: false
73
73
  requirements:
74
74
  - - ! '>='
@@ -76,10 +76,10 @@ dependencies:
76
76
  version: '0'
77
77
  type: :runtime
78
78
  prerelease: false
79
- version_requirements: *13348780
79
+ version_requirements: *21484020
80
80
  - !ruby/object:Gem::Dependency
81
81
  name: zfben_hanoi
82
- requirement: &13346760 !ruby/object:Gem::Requirement
82
+ requirement: &21483480 !ruby/object:Gem::Requirement
83
83
  none: false
84
84
  requirements:
85
85
  - - ! '>='
@@ -87,7 +87,7 @@ dependencies:
87
87
  version: '0'
88
88
  type: :development
89
89
  prerelease: false
90
- version_requirements: *13346760
90
+ version_requirements: *21483480
91
91
  description: ''
92
92
  email:
93
93
  - ben@zfben.com
@@ -97,7 +97,7 @@ extensions: []
97
97
  extra_rdoc_files: []
98
98
  files:
99
99
  - .gitignore
100
- - README.rdoc
100
+ - README.md
101
101
  - Rakefile
102
102
  - bin/libjs
103
103
  - lib/zfben_libjs.rb
@@ -116,11 +116,13 @@ files:
116
116
  - lib/zfben_libjs/support_source/sass.rb
117
117
  - lib/zfben_libjs/support_source/scss.rb
118
118
  - test.yml
119
+ - test/custom_filetype.mustache
119
120
  - test/javascript/assets/callback.js
120
121
  - test/javascript/fixtures/lib_fixtures.html
121
122
  - test/javascript/lib_test.js
122
123
  - test/javascript/templates/test_case.erb
123
124
  - test/load_times.js
125
+ - test/mustache.rb
124
126
  - test/route_regexp.js
125
127
  - test/route_string.js
126
128
  - test/ruby/build_test.rb
data/README.rdoc DELETED
@@ -1,87 +0,0 @@
1
- = Lib.js
2
-
3
- Lib.js = Frontend build tool + lazyload js tool
4
-
5
- == Getting Started
6
-
7
- 1. Install zfben_libjs
8
-
9
- gem install zfben_libjs
10
-
11
- 2. Create new libjs project
12
-
13
- libjs new
14
-
15
- == Feature:
16
-
17
- lazyload css and js files (base on LazyLoad.js)
18
-
19
- support css, js and images files
20
-
21
- support sass, scss, compass and coffeescript files
22
-
23
- support local files and remote files
24
-
25
- support custom ruby script
26
-
27
- support minify css and js files (base on sass and uglifier)
28
-
29
- support before and after events
30
-
31
- == Support Filetype:
32
-
33
- .css - stylesheet
34
-
35
- .js - javascript
36
-
37
- .sass - sass
38
-
39
- .scss - scss
40
-
41
- .coffee - coffeescript
42
-
43
- .rb - ruby
44
-
45
- == Javascript Example
46
-
47
- // load jquery
48
- lib.jquery(function(){
49
- // something use jquery to do
50
- });
51
-
52
- // load jqueryui and not duplicate load jquery
53
- lib.jqueryui(function(){
54
- // something use jqueryui to do
55
- });
56
-
57
- // and you can load like
58
- lib('jquery', function(){
59
- // use jquery to do sth.
60
- });
61
-
62
- lib('jquery underscore', function(){
63
- // use jquery and underscore to do sth.
64
- });
65
-
66
- == Rails Example
67
-
68
- # Gemfile
69
- gem 'zfben_libjs'
70
-
71
- # layout.html.erb
72
-
73
- <%= lib %>
74
- # => <script src="/javascripts/lib.js?12345678"></script>
75
-
76
- <%= lib :home %>
77
- # => <script src="/javascripts/lib.js?12345678"></script><script>lib('home')</script>
78
-
79
- <%= lib 'home.css' %>
80
- # => <link rel="stylesheet" href="/stylesheets/home.css?12345678" /><script src="/javascripts/lib.js?12345678"></script>
81
-
82
- <%= lib 'home.js' %>
83
- # => <script src="/javascripts/home.js?12345678"></script><script src="/javascripts/lib.js?12345678"></script>
84
-
85
- == Sinatra
86
-
87
- helpers Zfben_libjs::Helpers