Permalink
Browse files

Use make and uglify.

  • Loading branch information...
benpickles committed Apr 30, 2012
1 parent b9423c1 commit 655a2becbfe50821e36295cb64b2df6e96f765f0
Showing with 42 additions and 95 deletions.
  1. +0 −2 Gemfile
  2. +0 −6 Gemfile.lock
  3. +35 −0 Makefile
  4. +0 −14 Rakefile
  5. +5 −7 { → docs}/lib/docs.rb
  6. +2 −2 docs/{ → lib}/template.erb
  7. 0 { → docs}/lib/toc.rb
  8. +0 −64 lib/bundler.rb
View
@@ -1,7 +1,5 @@
source 'http://rubygems.org'
-gem 'closure-compiler'
-gem 'fewer', '~> 0.2.0'
gem 'highlight', :require => 'simplabs/highlight'
gem 'nokogiri'
gem 'rdiscount'
View
@@ -3,22 +3,16 @@ GEM
specs:
activesupport (3.1.3)
multi_json (~> 1.0)
- closure-compiler (1.0.0)
- fewer (0.2.0)
- rack
highlight (1.1.3)
activesupport (>= 2.0.0)
multi_json (1.0.4)
nokogiri (1.5.0)
- rack (1.2.1)
rdiscount (1.6.8)
PLATFORMS
ruby
DEPENDENCIES
- closure-compiler
- fewer (~> 0.2.0)
highlight
nokogiri
rdiscount
View
@@ -0,0 +1,35 @@
+SRC = src/header.js \
+ src/model.js \
+ src/model_version.js \
+ src/model_utils.js \
+ src/event_emitter.js \
+ src/model_uid.js \
+ src/model_model.js \
+ src/model_class_methods.js \
+ src/model_errors.js \
+ src/collection.js \
+ src/model_log.js \
+ src/model_rest.js \
+ src/null_persistence.js \
+ src/model_local_storage.js \
+ src/indexer.js
+
+VERSION = $(shell cat VERSION)
+
+js-model.js: $(SRC)
+ cat $^ | \
+ sed "s/@VERSION/${VERSION}/" > $@
+
+js-model.min.js: js-model.js
+ uglifyjs < $< > $@
+
+all:
+ make clean docs
+
+clean:
+ rm -f js-model.js js-model.min.js
+
+docs: js-model.min.js
+ ruby -rubygems -rbundler/setup -Idocs/lib -rdocs -e "puts Docs.build" > index.html
+
+.PHONY: docs
View
@@ -1,14 +0,0 @@
-$: << 'lib'
-
-autoload :Bundler, 'bundler'
-autoload :Docs, 'docs'
-
-desc 'Create bundled and minified source files.'
-task :bundle do
- Bundler.bundle!
-end
-
-desc 'Build docs.'
-task :docs do
- Docs.build
-end
@@ -7,7 +7,7 @@
class Docs
class << self
def build
- @version = File.read(File.expand_path('../../VERSION', __FILE__)).chomp
+ @version = File.read(File.expand_path('../../../VERSION', __FILE__)).chomp
@file_size = file_size
@file_size_min = file_size(:min)
@sections = [
@@ -35,9 +35,7 @@ def build
end
end
- File.open(File.expand_path('../../index.html', __FILE__), 'w') do |f|
- f.write doc.to_html
- end
+ doc.to_html
end
private
@@ -58,17 +56,17 @@ def analytics
end
def file_size(min = nil)
- bytes = File.size(File.expand_path("../../dist/js-model-#{@version}#{'.min' if min}.js", __FILE__))
+ bytes = File.size(File.expand_path("../../../js-model#{'.min' if min}.js", __FILE__))
'%.1f' % (bytes.to_f / 1000)
end
def markdown(file_name)
- md = File.expand_path("../../docs/#{file_name}.md", __FILE__)
+ md = File.expand_path("../../#{file_name}.md", __FILE__)
RDiscount.new(File.read(md), :smart).to_html
end
def template
- File.read(File.expand_path('../../docs/template.erb', __FILE__))
+ File.read(File.expand_path('../template.erb', __FILE__))
end
end
end
@@ -13,8 +13,8 @@
<dl>
<dt>Download</dt>
- <dd><a href="dist/js-model-<%= @version %>.min.js">js-model-<%= @version %>.min.js</a> (<%= @file_size_min %>Kb)</dd>
- <dd><a href="dist/js-model-<%= @version %>.js">js-model-<%= @version %>.js</a> (<%= @file_size %>Kb)</dd>
+ <dd><a href="js-model.min.js">js-model.min.js</a> (<%= @file_size_min %>Kb)</dd>
+ <dd><a href="js-model.js">js-model.js</a> (<%= @file_size %>Kb)</dd>
<dt>Source</dt>
<dd><a href="http://github.com/benpickles/js-model">github.com/benpickles/js-model</a></dd>
File renamed without changes.
View
@@ -1,64 +0,0 @@
-require 'fileutils'
-
-require 'rubygems'
-require 'closure-compiler'
-require 'fewer'
-
-class Bundler
- DIST_DIR = File.expand_path('../../dist', __FILE__)
- SRC_DIR = File.expand_path('../../src', __FILE__)
-
- class << self
- def bundle!
- FileUtils.mkdir_p(DIST_DIR)
-
- write "#{DIST_DIR}/js-model-#{version}.js" do
- Fewer::Engines::Js.new(SRC_DIR, files).read
- end
-
- write "#{DIST_DIR}/js-model-#{version}.min.js" do
- Fewer::Engines::Js.new(SRC_DIR, files, :min => true).read
- end
- end
-
- def bundled
- Fewer::Engines::Js.new(SRC_DIR, files).read
- end
-
- private
- def files
- @files ||= %w(
- model
- model_callbacks
- model_class_methods
- model_errors
- model_instance_methods
- model_local_storage
- model_log
- model_module
- model_rest
- model_uid
- model_utils
- model_version
- model_base
- )
- end
-
- def header
- @header ||= File.read(File.join(SRC_DIR, 'header.js'))
- end
-
- def version
- @version ||= File.read('VERSION').strip
- end
-
- def write(path, &block)
- puts "Generating #{path}"
-
- File.open(path, 'w') do |f|
- f.write header.gsub('@VERSION', version)
- f.write yield.gsub('@VERSION', version)
- end
- end
- end
-end

0 comments on commit 655a2be

Please sign in to comment.