zfben_libjs 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.rdoc ADDED
@@ -0,0 +1,52 @@
1
+ == SUMMARY
2
+
3
+ Lib.js = Frontend build tool + lazyload js tool
4
+
5
+ Feature:
6
+
7
+ lazyload css and js files (base on LazyLoad.js)
8
+ css, js and images files
9
+ sass, scss, compass and coffeescript files
10
+ local files and remote files
11
+ custom ruby script
12
+ minify css and js files (base on sass and uglifier)
13
+
14
+ Support Filetype:
15
+
16
+ .css - stylesheet
17
+ .js - javascript
18
+ .sass - sass
19
+ .scss - scss
20
+ .coffee - coffeescript
21
+ .rb - ruby
22
+
23
+ == Example
24
+
25
+ // load jquery
26
+ lib.jquery(function(){
27
+ // something use jquery to do
28
+ });
29
+
30
+ // load jqueryui and not duplicate load jquery
31
+ lib.jqueryui(function(){
32
+ // something use jqueryui to do
33
+ });
34
+
35
+ // and you can load like
36
+ lib('jquery', function(){
37
+ // use jquery to do sth.
38
+ });
39
+
40
+ lib('jquery underscore', function(){
41
+ // use jquery and underscore to do sth.
42
+ });
43
+
44
+ == Getting Started
45
+
46
+ 1. Install zfben_libjs
47
+
48
+ gem install zfben_libjs
49
+
50
+ 2. Create new libjs project
51
+
52
+ libjs new
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
+ require 'rubygems'
1
2
  require 'bundler/gem_tasks'
3
+
4
+ require 'rspec/core/rake_task'
5
+
6
+ RSpec::Core::RakeTask.new(:test)
data/lib/zfben_libjs.rb CHANGED
@@ -32,13 +32,14 @@ class Libjs
32
32
  err "#{@config_file} load filed!\n#{e}"
33
33
  end
34
34
 
35
- tip "#{@config_file} load success!"
35
+ @path_gem = File.realpath(File.join(File.dirname(__FILE__), 'zfben_libjs'))
36
+ @path_lib = File.realpath('.')
36
37
 
37
- p @data
38
+ tip "#{@config_file} load success!"
38
39
  end
39
40
 
40
41
  def build!
41
- print '== Starting Build @' + @config_file
42
+ tip '== Starting Build @' + @config_file
42
43
 
43
44
  # Merge default config
44
45
  @config = {
@@ -76,12 +77,12 @@ class Libjs
76
77
  end
77
78
 
78
79
 
79
- p '== [1/2] Starting Progress Source =='
80
+ tip '== [1/2] Starting Progress Source =='
80
81
  length = @libs.length
81
82
  num = 0
82
83
  @libs.each do |name, urls|
83
84
  num = num + 1
84
- p "[#{num}/#{length}] #{name}"
85
+ tip "[#{num}/#{length}] #{name}"
85
86
  urls = [urls] unless urls.class == Array
86
87
  lib = []
87
88
  urls.each do |url|
@@ -224,13 +225,13 @@ class Libjs
224
225
  @libs[name] = @libs[name][0] if @libs[name].length == 1
225
226
  end
226
227
 
227
- p '== [2/2] Generate lib.js =='
228
+ tip '== [2/2] Generate lib.js =='
228
229
 
229
230
  libjs = File.read(@libs['lazyload']) << ';'
230
231
 
231
- libjs_core = CoffeeScript.compile(File.read(File.join(File.dirname(__FILE__), 'zfben_libjs', 'lib.coffee')))
232
+ libjs_core = File.read(File.join(@path_gem, 'lib.coffee'))
232
233
 
233
- libjs << (@config['minify'] ? minify(libjs_core, :js) : @config['minify'])
234
+ libjs << CoffeeScript.compile(libjs_core)
234
235
 
235
236
  @urls = {}
236
237
  @libs.each do |lib, path|
@@ -300,12 +301,14 @@ class Libjs
300
301
  if @preload.class == Array && @preload.length > 0
301
302
  libjs << "\n/* preload */\nlib('#{@preload.join(' ')}');"
302
303
  end
304
+
305
+ libjs = minify(libjs, :js) if @config['minify']
303
306
  File.open(File.join(@config['src/javascripts'], 'lib.js'), 'w'){ |f| f.write(libjs) }
304
307
 
305
308
  if @config.has_key?('after')
306
309
  load @config['after']
307
310
  end
308
311
 
309
- p '== End Build =='
312
+ tip '== End Build =='
310
313
  end
311
314
  end
@@ -1,3 +1,3 @@
1
1
  module ZfbenLibjs
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,15 @@
1
+ require File.realpath(File.join(File.dirname(__FILE__), '..', '..', 'lib', 'zfben_libjs.rb'))
2
+ SPEC_PATH = File.realpath(File.dirname(__FILE__))
3
+
4
+ describe Libjs do
5
+ it "when pass nothing to Libjs.new" do
6
+ begin
7
+ Libjs.new
8
+ rescue => e
9
+ e.message
10
+ end
11
+ end
12
+ it "when pass a filename to Libjs.new" do
13
+ Libjs.new(File.join(SPEC_PATH, 'spec'))
14
+ end
15
+ end
File without changes
data/zfben_libjs.gemspec CHANGED
@@ -11,8 +11,7 @@ Gem::Specification.new do |s|
11
11
  s.summary = %q{}
12
12
  s.description = %q{}
13
13
 
14
- s.post_install_message =%q{
15
- ********************************************************************************
14
+ s.post_install_message =%q{********************************************************************************
16
15
  Thank you for using zfben_libjs!
17
16
 
18
17
  Please follow @zfben on Twitter for announcements, updates, and news.
@@ -32,7 +31,6 @@ Gem::Specification.new do |s|
32
31
  s.add_dependency 'rainbow'
33
32
  s.add_dependency 'json'
34
33
  s.add_dependency 'compass'
35
- s.add_dependency 'mustang'
36
34
  s.add_dependency 'coffee-script'
37
35
  s.add_dependency 'uglifier'
38
36
 
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: zfben_libjs
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.0.1
5
+ version: 0.0.2
6
6
  platform: ruby
7
7
  authors:
8
8
  - Ben
@@ -10,7 +10,7 @@ autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
12
 
13
- date: 2011-07-31 00:00:00 +08:00
13
+ date: 2011-08-03 00:00:00 +08:00
14
14
  default_executable:
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
@@ -47,7 +47,7 @@ dependencies:
47
47
  type: :runtime
48
48
  version_requirements: *id003
49
49
  - !ruby/object:Gem::Dependency
50
- name: mustang
50
+ name: coffee-script
51
51
  prerelease: false
52
52
  requirement: &id004 !ruby/object:Gem::Requirement
53
53
  none: false
@@ -58,7 +58,7 @@ dependencies:
58
58
  type: :runtime
59
59
  version_requirements: *id004
60
60
  - !ruby/object:Gem::Dependency
61
- name: coffee-script
61
+ name: uglifier
62
62
  prerelease: false
63
63
  requirement: &id005 !ruby/object:Gem::Requirement
64
64
  none: false
@@ -68,17 +68,6 @@ dependencies:
68
68
  version: "0"
69
69
  type: :runtime
70
70
  version_requirements: *id005
71
- - !ruby/object:Gem::Dependency
72
- name: uglifier
73
- prerelease: false
74
- requirement: &id006 !ruby/object:Gem::Requirement
75
- none: false
76
- requirements:
77
- - - ">="
78
- - !ruby/object:Gem::Version
79
- version: "0"
80
- type: :runtime
81
- version_requirements: *id006
82
71
  description: ""
83
72
  email:
84
73
  - ben@zfben.com
@@ -90,7 +79,7 @@ extra_rdoc_files: []
90
79
 
91
80
  files:
92
81
  - .gitignore
93
- - Gemfile
82
+ - README.rdoc
94
83
  - Rakefile
95
84
  - bin/libjs
96
85
  - lib/zfben_libjs.rb
@@ -98,14 +87,21 @@ files:
98
87
  - lib/zfben_libjs/lib.rb
99
88
  - lib/zfben_libjs/libjs.yml
100
89
  - lib/zfben_libjs/version.rb
90
+ - spec/ruby/libjs_spec.rb
91
+ - spec/ruby/spec.yml
101
92
  - zfben_libjs.gemspec
102
93
  has_rdoc: true
103
94
  homepage: ""
104
95
  licenses: []
105
96
 
106
- post_install_message: "\n\
107
- ********************************************************************************\n Thank you for using zfben_libjs!\n \n Please follow @zfben on Twitter for announcements, updates, and news.\n https://twitter.com/zfben\n\
108
- ********************************************************************************\n"
97
+ post_install_message: |
98
+ ********************************************************************************
99
+ Thank you for using zfben_libjs!
100
+
101
+ Please follow @zfben on Twitter for announcements, updates, and news.
102
+ https://twitter.com/zfben
103
+ ********************************************************************************
104
+
109
105
  rdoc_options: []
110
106
 
111
107
  require_paths:
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'http://rubygems.org'
2
- gem 'json'
3
- gem 'therubyracer'
4
- gem 'coffee-script'
5
- gem 'uglifier'
6
- gem 'compass'
7
- gem 'sinatra'
8
- gem 'watchr'
9
- gem 'rainbow'