join 0.0.2

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.
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in join.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require 'bundler/gem_tasks'
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ require "rubygems"
3
+ libdir = File.join(File.dirname(File.dirname(__FILE__)), "lib")
4
+ $LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
5
+
6
+ require 'join'
7
+
8
+ #Get command line args
9
+ args = ARGV.dup.unshift()
10
+ dir = Dir.pwd
11
+
12
+ if ARGV.empty?
13
+ STDOUT.puts "You must supply a filename or directory"
14
+ else
15
+ join = Join::Concatenation.new(dir)
16
+ modules = join.find_required_modules(args[0])
17
+ join.concat(modules, args[1], args[0])
18
+ end
19
+
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "join/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "join"
7
+ s.version = Join::VERSION
8
+ s.authors = ["Owain Lewis"]
9
+ s.email = ["owain@owainlewis.com"]
10
+ s.homepage = ""
11
+ s.summary = %q{A Ruby library for joining files together. Principally aimed at joining JavaScript modules}
12
+ s.description = %q{A Ruby library for joining files together. Principally aimed at joining JavaScript modules}
13
+
14
+ s.rubyforge_project = "join"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
@@ -0,0 +1,14 @@
1
+ $:.unshift File.dirname(__FILE__)
2
+ require "join/version"
3
+ require "fileutils"
4
+
5
+ module Join
6
+ class << self
7
+ def message(m)
8
+ STDOUT.puts m
9
+ end
10
+ end
11
+ end
12
+
13
+ require 'join/process'
14
+ require 'join/concatenate'
@@ -0,0 +1,67 @@
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
@@ -0,0 +1,19 @@
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 = /^\/\/=\s?(.*)$/
13
+ file.scan(expr) do |m|
14
+ @required_modules << m
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,6 @@
1
+ module Join
2
+ MAJOR_VERSION = 0
3
+ MINOR = 0
4
+ TINY = 2
5
+ VERSION = [MAJOR_VERSION, MINOR, TINY].join(".")
6
+ end
@@ -0,0 +1,7 @@
1
+ #Join
2
+
3
+ Join is a Ruby gem for concatenating together multiple JavaScript files and libraries ready for deployment.
4
+ Each JavaScript module is created with a time stamp and a path to the original source file.
5
+
6
+ gem install join
7
+ join-files /javascripts compressed.js
metadata ADDED
@@ -0,0 +1,58 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: join
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Owain Lewis
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2011-08-28 00:00:00.000000000Z
13
+ dependencies: []
14
+ description: A Ruby library for joining files together. Principally aimed at joining
15
+ JavaScript modules
16
+ email:
17
+ - owain@owainlewis.com
18
+ executables:
19
+ - join-files
20
+ extensions: []
21
+ extra_rdoc_files: []
22
+ files:
23
+ - .gitignore
24
+ - Gemfile
25
+ - Rakefile
26
+ - bin/join-files
27
+ - join.gemspec
28
+ - lib/join.rb
29
+ - lib/join/concatenate.rb
30
+ - lib/join/process.rb
31
+ - lib/join/version.rb
32
+ - readme.md
33
+ homepage: ''
34
+ licenses: []
35
+ post_install_message:
36
+ rdoc_options: []
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ none: false
47
+ requirements:
48
+ - - ! '>='
49
+ - !ruby/object:Gem::Version
50
+ version: '0'
51
+ requirements: []
52
+ rubyforge_project: join
53
+ rubygems_version: 1.8.5
54
+ signing_key:
55
+ specification_version: 3
56
+ summary: A Ruby library for joining files together. Principally aimed at joining JavaScript
57
+ modules
58
+ test_files: []