join 0.0.3 → 0.0.5
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/bin/{join-compile → join} +4 -8
- data/lib/join.rb +21 -11
- data/lib/join/compiler.rb +74 -0
- data/lib/join/compressor.rb +38 -0
- data/lib/join/version.rb +1 -1
- data/lib/src/1.css +40 -0
- data/lib/src/1.js +3 -0
- data/lib/src/2.css +23 -0
- data/lib/src/2.js +6 -0
- data/readme.md +13 -56
- data/test/tc_join.rb +2 -0
- metadata +12 -13
- data/index.js +0 -0
- data/lib/join/concatenate.rb +0 -67
- data/lib/join/process.rb +0 -19
- data/test/compiled.js +0 -22
- data/test/include.js +0 -5
- data/test/index.js +0 -4
data/bin/{join-compile → join}
RENAMED
@@ -8,13 +8,9 @@ require 'join'
|
|
8
8
|
|
9
9
|
#Get command line args
|
10
10
|
args = ARGV.dup.unshift()
|
11
|
-
dir = Dir.pwd
|
12
11
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
modules = join.find_required_modules(args[0])
|
18
|
-
join.concat(modules, args[1], args[0])
|
19
|
-
end
|
12
|
+
compiler = Join::Compiler.new({:dest => "compiled.js", :compressed => true})
|
13
|
+
compiler.join(args)
|
14
|
+
|
15
|
+
|
20
16
|
|
data/lib/join.rb
CHANGED
@@ -1,20 +1,30 @@
|
|
1
|
-
# Copyright (c)
|
1
|
+
# Copyright (c) Owain Lewis. owain@owainlewis.com
|
2
2
|
# All files in this distribution are subject to the terms of the Ruby license.
|
3
3
|
|
4
|
+
# Join is an asset packer that joins together multiple files into one, typically for deployment
|
5
|
+
# If required, Join will compress JavaScript files with the Google Closure compiler
|
6
|
+
|
4
7
|
$:.unshift File.dirname(__FILE__)
|
5
8
|
|
6
|
-
require
|
7
|
-
require "join/version"
|
8
|
-
require 'join/process'
|
9
|
-
require 'join/concatenate'
|
9
|
+
require 'join/version'
|
10
10
|
|
11
11
|
module Join
|
12
|
-
|
13
|
-
class << self
|
14
|
-
def message(m)
|
15
|
-
STDOUT.puts m
|
16
|
-
end
|
17
|
-
end
|
18
12
|
|
13
|
+
ROOT = File.expand_path(File.dirname(__FILE__) + '/')
|
14
|
+
|
15
|
+
COMPRESS = false
|
16
|
+
|
17
|
+
autoload :Base, 'join/base'
|
18
|
+
autoload :Compiler, 'join/compiler'
|
19
|
+
autoload :Assets, 'join/asset_processor'
|
20
|
+
autoload :Compressor, 'join/compressor'
|
21
|
+
|
19
22
|
end
|
20
23
|
|
24
|
+
compiler = Join::Compiler.new({:dest => "compiled", :compressed => true})
|
25
|
+
|
26
|
+
compiler.join([
|
27
|
+
'src/1.css',
|
28
|
+
'src/2.css'
|
29
|
+
])
|
30
|
+
|
@@ -0,0 +1,74 @@
|
|
1
|
+
module Join
|
2
|
+
|
3
|
+
# Takes multiple files and compiles them into a single file
|
4
|
+
class Compiler
|
5
|
+
|
6
|
+
attr_reader :options
|
7
|
+
|
8
|
+
def initialize(opts = {})
|
9
|
+
@dest = opts[:dest] || 'compressed.js'
|
10
|
+
@compressed = opts[:compressed] || false
|
11
|
+
@compressor = Join::Compressor.new
|
12
|
+
end
|
13
|
+
|
14
|
+
F_TYPES = {
|
15
|
+
:javascript => '.js',
|
16
|
+
:css => '.css'
|
17
|
+
}
|
18
|
+
|
19
|
+
# Delete or flush the contents of a given file.
|
20
|
+
def flush!(file)
|
21
|
+
File.open(file, 'w').truncate(0)
|
22
|
+
end
|
23
|
+
|
24
|
+
# We need this to determine what type of file we are dealing with
|
25
|
+
# before sending the data to the file compressor
|
26
|
+
def get_file_type(ext)
|
27
|
+
F_TYPES.key(ext)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Open a file and append data to the file.
|
31
|
+
def append_to(filename, data)
|
32
|
+
begin
|
33
|
+
File.open(filename, 'a') do |f|
|
34
|
+
if @compressed == true
|
35
|
+
ext = get_ext(filename)
|
36
|
+
type = get_file_type(ext)
|
37
|
+
data = @compressor.compress(type, data)
|
38
|
+
end
|
39
|
+
f.puts data
|
40
|
+
end
|
41
|
+
show_success_message
|
42
|
+
rescue
|
43
|
+
STDOUT.puts "Cannot append to file"
|
44
|
+
exit #Terminate if file can't be found
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_ext(path)
|
49
|
+
File.extname(path)
|
50
|
+
end
|
51
|
+
|
52
|
+
def show_success_message
|
53
|
+
STDOUT.puts "Successfully joined file for production"
|
54
|
+
end
|
55
|
+
|
56
|
+
def read_file(path)
|
57
|
+
raise "File does not exist" unless File.exists?(path)
|
58
|
+
File.open(path, 'r') do |f|
|
59
|
+
f.read
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
# When given an array of files, (e.g [file1.js, file2.js])
|
64
|
+
# join them together and output the result
|
65
|
+
# into the destination set in @options
|
66
|
+
def join(args)
|
67
|
+
flush!(@dest) if File.exists? @dest #Empty file if it already exists
|
68
|
+
result = args.map { |p| read_file(p) }.join("\n")
|
69
|
+
append_to(@dest, result)
|
70
|
+
end
|
71
|
+
|
72
|
+
end
|
73
|
+
|
74
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
module Join
|
2
|
+
|
3
|
+
# Files get sent through the asset compressor
|
4
|
+
# to be minified before deployment
|
5
|
+
|
6
|
+
class Compressor
|
7
|
+
|
8
|
+
require 'closure-compiler'
|
9
|
+
|
10
|
+
class UnknownTypeError < StandardError; end
|
11
|
+
|
12
|
+
def compress(type, data)
|
13
|
+
if type == :javascript
|
14
|
+
compress_javascript(data)
|
15
|
+
elsif type == :css
|
16
|
+
compress_css(data)
|
17
|
+
else
|
18
|
+
throw UnknownTypeError
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def compress_javascript(data)
|
23
|
+
Closure::Compiler.new.compile(data)
|
24
|
+
end
|
25
|
+
|
26
|
+
def compress_css(data)
|
27
|
+
data.gsub!(/\s+/, " ") #remove space
|
28
|
+
data.gsub(/\s/, '')
|
29
|
+
data.gsub!(/\/\*(.*?)\*\//, "") # remove comments
|
30
|
+
data.gsub!(/\n$/, "") # remove last break
|
31
|
+
data.gsub!(/ \{ /, " {") # trim inside brackets
|
32
|
+
data.gsub!(/; \}/, "}") # trim inside brackets
|
33
|
+
data
|
34
|
+
end
|
35
|
+
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
data/lib/join/version.rb
CHANGED
data/lib/src/1.css
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
hr {
|
2
|
+
display: block;
|
3
|
+
height: 1px;
|
4
|
+
border: 0;
|
5
|
+
border-top: 1px solid #cccccc;
|
6
|
+
margin: 20px 0 19px 0;
|
7
|
+
padding: 0; }
|
8
|
+
|
9
|
+
input, select {
|
10
|
+
vertical-align: middle; }
|
11
|
+
|
12
|
+
textarea {
|
13
|
+
overflow: auto; }
|
14
|
+
|
15
|
+
.ie6 legend, .ie7 legend {
|
16
|
+
margin-left: -7px; }
|
17
|
+
|
18
|
+
input[wtype="radio"] {
|
19
|
+
vertical-align: text-bottom; }
|
20
|
+
|
21
|
+
input[type="checkbox"] {
|
22
|
+
vertical-align: bottom; }
|
23
|
+
|
24
|
+
.ie7 input[type="checkbox"] {
|
25
|
+
vertical-align: baseline; }
|
26
|
+
|
27
|
+
.ie6 input {
|
28
|
+
vertical-align: text-bottom; }
|
29
|
+
|
30
|
+
label, input[type="button"], input[type="submit"], input[type="image"], button {
|
31
|
+
cursor: pointer; }
|
32
|
+
|
33
|
+
button, input, select, textarea {
|
34
|
+
margin: 0; }
|
35
|
+
|
36
|
+
body, h1, h2, h3, h4, h5, h6, p, ul, ol, dl, input, textarea {
|
37
|
+
line-height: 20px;
|
38
|
+
font-family: "Helvetica Neue", Helvetica, Arial, sans-serif;
|
39
|
+
color: gray;
|
40
|
+
font-size: 13px; }
|
data/lib/src/1.js
ADDED
data/lib/src/2.css
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
/* --------------------------------------------------------------
|
2
|
+
* Gravity CSS
|
3
|
+
* Version 0.1
|
4
|
+
* Developed by: Owain Lewis
|
5
|
+
* www.owainlewis.com
|
6
|
+
* License: MIT
|
7
|
+
* http://www.opensource.org/licenses/mit-license.php
|
8
|
+
*-------------------------------------------------------------- */
|
9
|
+
html, body, div, span, object, iframe,
|
10
|
+
h1, h2, h3, h4, h5, h6, p, blockquote, pre,
|
11
|
+
abbr, address, cite, code, del, dfn, em, img, ins, kbd, q, samp,
|
12
|
+
small, strong, sub, sup, var, b, i, dl, dt, dd, ol, ul, li,
|
13
|
+
fieldset, form, label, legend,
|
14
|
+
table, caption, tbody, tfoot, thead, tr, th, td,
|
15
|
+
article, aside, canvas, details, figcaption, figure,
|
16
|
+
footer, header, hgroup, menu, nav, section, summary,
|
17
|
+
time, mark, audio, video {
|
18
|
+
margin: 0;
|
19
|
+
padding: 0;
|
20
|
+
border: 0;
|
21
|
+
font-size: 100%;
|
22
|
+
font: inherit;
|
23
|
+
vertical-align: baseline; }
|
data/readme.md
CHANGED
@@ -1,68 +1,25 @@
|
|
1
1
|
#Join
|
2
2
|
|
3
|
-
Join is
|
4
|
-
|
5
|
-
+ To provide a pseudo common.js module system for the browser. //= require myfile.js
|
6
|
-
+ To reduce the number of script tag calls on websites
|
7
|
-
+ To make combining multiple js files easier.
|
8
|
-
|
9
|
-
Each JavaScript module is created with a time stamp and a path to the original source file.
|
3
|
+
Join is an asset manager for concatenating together files for deployment.
|
10
4
|
|
11
5
|
##Installation
|
12
6
|
|
13
|
-
|
7
|
+
gem install join
|
14
8
|
|
15
9
|
##Usage
|
16
|
-
|
17
|
-
The basic idea is to have one main.js file that calls in other dependencies via a simple join statement:
|
18
10
|
|
19
|
-
|
11
|
+
join file1.js file2.js file3.js
|
12
|
+
|
13
|
+
##Calling directly
|
20
14
|
|
21
|
-
You can
|
15
|
+
You can call the join compiler directly by using the compiler
|
22
16
|
|
23
|
-
|
24
|
-
//= require lightbox.js
|
25
|
-
//= require plugins/jquery.js
|
26
|
-
|
27
|
-
(function(){
|
28
|
-
//Application code here
|
29
|
-
})();
|
30
|
-
|
31
|
-
Then run the join-files command in the terminal to join together all your files
|
32
|
-
|
33
|
-
join-compile source_file.js output_file.js
|
34
|
-
|
35
|
-
Sample output should be something like this:
|
17
|
+
compiler = Join::Compiler.new({:dest => "compiled.js", :compressed => true})
|
36
18
|
|
37
|
-
|
38
|
-
Compiled with Join at 2011-08-28 23:11:02 +0100
|
39
|
-
from /Users/owainlewis/Projects/Ruby/jointest/app/other.js
|
40
|
-
*/
|
41
|
-
|
42
|
-
Object.keys = function( obj ) {
|
43
|
-
var array = new Array();
|
44
|
-
for ( var prop in obj ) {
|
45
|
-
if ( obj.hasOwnProperty( prop ) ) {
|
46
|
-
array.push( prop );
|
47
|
-
}
|
48
|
-
}
|
49
|
-
return array;
|
50
|
-
};
|
51
|
-
|
52
|
-
/*
|
53
|
-
Compiled with Join at 2011-08-28 23:11:02 +0100
|
54
|
-
from /Users/owainlewis/Projects/Ruby/jointest/app/main.js
|
55
|
-
*/
|
56
|
-
|
57
|
-
//Main File
|
58
|
-
//= other.js
|
59
|
-
|
60
|
-
Object.defineProperties = function( obj, props ) {
|
61
|
-
for ( var prop in props ) {
|
62
|
-
Object.defineProperty( obj, prop, props[prop] );
|
63
|
-
}
|
64
|
-
};
|
65
|
-
|
66
|
-
## Known issues
|
19
|
+
#Join the following files into compiled.js
|
67
20
|
|
68
|
-
|
21
|
+
compiler.join([
|
22
|
+
'src/1.js',
|
23
|
+
'src/2.js'
|
24
|
+
])
|
25
|
+
|
data/test/tc_join.rb
ADDED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: join
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.5
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,31 +9,32 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-09-
|
12
|
+
date: 2011-09-18 00:00:00.000000000Z
|
13
13
|
dependencies: []
|
14
14
|
description: A Ruby library for joining files together. Principally aimed at joining
|
15
15
|
JavaScript modules
|
16
16
|
email:
|
17
17
|
- owain@owainlewis.com
|
18
18
|
executables:
|
19
|
-
- join
|
19
|
+
- join
|
20
20
|
extensions: []
|
21
21
|
extra_rdoc_files: []
|
22
22
|
files:
|
23
23
|
- .gitignore
|
24
24
|
- Gemfile
|
25
25
|
- Rakefile
|
26
|
-
- bin/join
|
27
|
-
- index.js
|
26
|
+
- bin/join
|
28
27
|
- join.gemspec
|
29
28
|
- lib/join.rb
|
30
|
-
- lib/join/
|
31
|
-
- lib/join/
|
29
|
+
- lib/join/compiler.rb
|
30
|
+
- lib/join/compressor.rb
|
32
31
|
- lib/join/version.rb
|
32
|
+
- lib/src/1.css
|
33
|
+
- lib/src/1.js
|
34
|
+
- lib/src/2.css
|
35
|
+
- lib/src/2.js
|
33
36
|
- readme.md
|
34
|
-
- test/
|
35
|
-
- test/include.js
|
36
|
-
- test/index.js
|
37
|
+
- test/tc_join.rb
|
37
38
|
homepage: ''
|
38
39
|
licenses: []
|
39
40
|
post_install_message:
|
@@ -60,6 +61,4 @@ specification_version: 3
|
|
60
61
|
summary: A Ruby library for joining files together. Principally aimed at joining JavaScript
|
61
62
|
modules
|
62
63
|
test_files:
|
63
|
-
- test/
|
64
|
-
- test/include.js
|
65
|
-
- test/index.js
|
64
|
+
- test/tc_join.rb
|
data/index.js
DELETED
File without changes
|
data/lib/join/concatenate.rb
DELETED
@@ -1,67 +0,0 @@
|
|
1
|
-
module Join
|
2
|
-
class Concatenation
|
3
|
-
|
4
|
-
attr_reader :files
|
5
|
-
|
6
|
-
def initialize(dir)
|
7
|
-
@files = []
|
8
|
-
@dir = dir
|
9
|
-
@process = ::Join::Process.new()
|
10
|
-
end
|
11
|
-
|
12
|
-
#Return all js files in a directory
|
13
|
-
def find_required_modules(dir)
|
14
|
-
@process.required(read(@dir + handlePrefix(dir)))
|
15
|
-
@process.required_modules()
|
16
|
-
end
|
17
|
-
|
18
|
-
#If the user omits a / from the path to the js folder we correct it for them
|
19
|
-
def handlePrefix(s)
|
20
|
-
if s.chars.first == '/'
|
21
|
-
s = s
|
22
|
-
else
|
23
|
-
s = '/' + s
|
24
|
-
end
|
25
|
-
s
|
26
|
-
end
|
27
|
-
|
28
|
-
def exists?(filename)
|
29
|
-
File.exists?(filename)
|
30
|
-
end
|
31
|
-
|
32
|
-
#Takes an array of files with absolute paths
|
33
|
-
def concat(files, dest, original)
|
34
|
-
File.new(dest, "w+") if !File.exists?(dest)
|
35
|
-
files.each do |f|
|
36
|
-
file = @dir + handlePrefix(f.fetch(0))
|
37
|
-
puts file
|
38
|
-
processFile(file) if exists?(file)
|
39
|
-
end
|
40
|
-
processFile(@dir + handlePrefix(original))
|
41
|
-
|
42
|
-
write(@files, dest)
|
43
|
-
::Join.message("Joined #{@files.length} files to #{@dir + handlePrefix(dest)}")
|
44
|
-
end
|
45
|
-
|
46
|
-
def processFile(file_name)
|
47
|
-
@files << "/*\nCompiled with Join at #{Time.now}\nfrom #{file_name}\n*/\n\n" + read(file_name) + "\n\n"
|
48
|
-
end
|
49
|
-
|
50
|
-
protected
|
51
|
-
|
52
|
-
def read(file_name)
|
53
|
-
file = File.open(file_name, "r")
|
54
|
-
contents = file.read
|
55
|
-
contents
|
56
|
-
end
|
57
|
-
|
58
|
-
#Write to file
|
59
|
-
def write(content, dest)
|
60
|
-
File.open(dest, 'w') do |file|
|
61
|
-
file.puts content
|
62
|
-
end
|
63
|
-
end
|
64
|
-
|
65
|
-
end
|
66
|
-
|
67
|
-
end
|
data/lib/join/process.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
module Join
|
2
|
-
class Process
|
3
|
-
|
4
|
-
attr_reader :required_modules
|
5
|
-
|
6
|
-
def initialize
|
7
|
-
@required_modules = []
|
8
|
-
end
|
9
|
-
|
10
|
-
#Return an array of required modules and files
|
11
|
-
def required(file)
|
12
|
-
expr = /^\/\/= require\s?(.*)$/
|
13
|
-
file.scan(expr) do |m|
|
14
|
-
@required_modules << m
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
end
|
19
|
-
end
|
data/test/compiled.js
DELETED
@@ -1,22 +0,0 @@
|
|
1
|
-
/*
|
2
|
-
Compiled with Join at 2011-09-11 18:16:25 +0100
|
3
|
-
from /Users/owainlewis/Projects/ruby/Gems/Join/test/include.js
|
4
|
-
*/
|
5
|
-
|
6
|
-
(function (){
|
7
|
-
|
8
|
-
/* Include.js */
|
9
|
-
|
10
|
-
}).call(this);
|
11
|
-
|
12
|
-
/*
|
13
|
-
Compiled with Join at 2011-09-11 18:16:25 +0100
|
14
|
-
from /Users/owainlewis/Projects/ruby/Gems/Join/test/index.js
|
15
|
-
*/
|
16
|
-
|
17
|
-
//= require include.js
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
data/test/include.js
DELETED
data/test/index.js
DELETED