From a519c02b2e1acf02dd6f8700c63d5cd2c14a8914 Mon Sep 17 00:00:00 2001 From: Sam Stephenson Date: Tue, 27 Jan 2009 15:42:32 -0600 Subject: [PATCH] Sprocketize Prototype --- Rakefile | 34 ++++++---- ext/update_helper/prototype_update_helper.js | 2 +- lib/protodoc.rb | 53 ---------------- src/HEADER | 7 --- src/ajax.js | 7 +++ src/constants.yml | 1 + src/dom.js | 6 ++ src/lang.js | 46 ++++++++++++++ src/prototype.js | 65 ++++---------------- vendor/sprockets | 2 +- 10 files changed, 96 insertions(+), 127 deletions(-) delete mode 100644 lib/protodoc.rb delete mode 100644 src/HEADER create mode 100644 src/ajax.js create mode 100644 src/constants.yml create mode 100644 src/dom.js create mode 100644 src/lang.js diff --git a/Rakefile b/Rakefile index cbaee1d..7a70ec4 100755 --- a/Rakefile +++ b/Rakefile @@ -12,17 +12,32 @@ PROTOTYPE_TMP_DIR = File.join(PROTOTYPE_TEST_UNIT_DIR, 'tmp') PROTOTYPE_VERSION = '1.6.0.3' $:.unshift File.join(PROTOTYPE_ROOT, 'lib') +$:.unshift File.join(PROTOTYPE_ROOT, 'vendor', 'sprockets', 'lib') task :default => [:dist, :dist_helper, :package, :clean_package_source] +def sprocketize(path, source, destination = source) + begin + require "sprockets" + rescue LoadError => e + puts "\nYou'll need Sprockets to build Prototype. Just run:\n\n" + puts " $ git submodule init" + puts " $ git submodule update" + puts "\nand you should be all set.\n\n" + end + + environment = Sprockets::Environment.new(File.join(PROTOTYPE_ROOT, path), [File.join(PROTOTYPE_ROOT, "src")]) + preprocessor = Sprockets::Preprocessor.new(environment) + preprocessor.require(environment.find(source).source_file) + + File.open(File.join(PROTOTYPE_DIST_DIR, destination), 'w+') do |dist| + dist.write(preprocessor.output_file) + end +end + desc "Builds the distribution." task :dist do - require 'protodoc' - - File.open(File.join(PROTOTYPE_DIST_DIR, 'prototype.js'), 'w+') do |dist| - source = File.join(PROTOTYPE_SRC_DIR, 'prototype.js') - dist << Protodoc::Preprocessor.new(source, :strip_documentation => true) - end + sprocketize("src", "prototype.js") end namespace :doc do @@ -56,12 +71,7 @@ task :doc => ['doc:build'] desc "Builds the updating helper." task :dist_helper do - require 'protodoc' - - File.open(File.join(PROTOTYPE_DIST_DIR, 'prototype_update_helper.js'), 'w+') do |dist| - source = File.join(PROTOTYPE_ROOT, 'ext', 'update_helper', 'prototype_update_helper.js') - dist << Protodoc::Preprocessor.new(source) - end + sprocketize("ext/update_helper", "prototype_update_helper.js") end Rake::PackageTask.new('prototype', PROTOTYPE_VERSION) do |package| diff --git a/ext/update_helper/prototype_update_helper.js b/ext/update_helper/prototype_update_helper.js index c3ce2f2..3cbc56a 100644 --- a/ext/update_helper/prototype_update_helper.js +++ b/ext/update_helper/prototype_update_helper.js @@ -1,4 +1,4 @@ -<%= include "update_helper.js" %> +//= require "update_helper" /* UpdateHelper for Prototype <%= PROTOTYPE_VERSION %> (c) 2008 Tobie Langel * diff --git a/lib/protodoc.rb b/lib/protodoc.rb deleted file mode 100644 index 37e3661..0000000 --- a/lib/protodoc.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'erb' - -class String - def lines - split $/ - end - - def strip_whitespace_at_line_ends - lines.map {|line| line.gsub(/\s+$/, '')} * $/ - end - - def strip_pdoc_comments - gsub %r{\s*/\*\*.*?\*\*/}m, "\n" - end -end - -module Protodoc - module Environment - def include(*filenames) - filenames.map do |filename| - Preprocessor.new(expand_path(filename), @options).result - end.join("\n") - end - end - - class Preprocessor - include Environment - - def initialize(filename, options = { }) - filename = File.join(filename.split('/')) - @filename = File.expand_path(filename) - @template = ERB.new(IO.read(@filename), nil, '%') - @options = options - end - - def expand_path(filename) - File.join(File.dirname(@filename), filename) - end - - def result - result = @template.result(binding) - result = result.strip_whitespace_at_line_ends - result = result.strip_pdoc_comments if @options[:strip_documentation] - result - end - - alias_method :to_s, :result - end -end - -if __FILE__ == $0 - print Protodoc::Preprocessor.new(ARGV.first) -end diff --git a/src/HEADER b/src/HEADER deleted file mode 100644 index c76e888..0000000 --- a/src/HEADER +++ /dev/null @@ -1,7 +0,0 @@ -/* Prototype JavaScript framework, version <%= PROTOTYPE_VERSION %> - * (c) 2005-2008 Sam Stephenson - * - * Prototype is freely distributable under the terms of an MIT-style license. - * For details, see the Prototype web site: http://www.prototypejs.org/ - * - *--------------------------------------------------------------------------*/ \ No newline at end of file diff --git a/src/ajax.js b/src/ajax.js new file mode 100644 index 0000000..98cf975 --- /dev/null +++ b/src/ajax.js @@ -0,0 +1,7 @@ +//= require "ajax/ajax" +//= require "ajax/responders" +//= require "ajax/base" +//= require "ajax/request" +//= require "ajax/response" +//= require "ajax/updater" +//= require "ajax/periodical_updater" diff --git a/src/constants.yml b/src/constants.yml new file mode 100644 index 0000000..3a05ed2 --- /dev/null +++ b/src/constants.yml @@ -0,0 +1 @@ +PROTOTYPE_VERSION: 1.6.0.3 diff --git a/src/dom.js b/src/dom.js new file mode 100644 index 0000000..c11aa68 --- /dev/null +++ b/src/dom.js @@ -0,0 +1,6 @@ +//= require "dom/dom" +//= require "dom/selector" +//= require "dom/form" +//= require "dom/event" + +Element.addMethods(); diff --git a/src/lang.js b/src/lang.js new file mode 100644 index 0000000..e21a180 --- /dev/null +++ b/src/lang.js @@ -0,0 +1,46 @@ +/** + * == lang == + * Language extensions. +**/ + +var Abstract = { }; + +/** section: lang + * Try +**/ + +/** + * Try.these(function...) -> ? + * - function (Function): A function that may throw an exception. + * Accepts an arbitrary number of functions and returns the result of the + * first one that doesn't throw an error. + **/ +var Try = { + these: function() { + var returnValue; + + for (var i = 0, length = arguments.length; i < length; i++) { + var lambda = arguments[i]; + try { + returnValue = lambda(); + break; + } catch (e) { } + } + + return returnValue; + } +}; + +//= require "lang/class" +//= require "lang/object" +//= require "lang/function" +//= require "lang/date" +//= require "lang/regexp" +//= require "lang/periodical_executer" +//= require "lang/string" +//= require "lang/template" +//= require "lang/enumerable" +//= require "lang/array" +//= require "lang/hash" +//= require "lang/number" +//= require "lang/range" diff --git a/src/prototype.js b/src/prototype.js index fb85404..166e02d 100644 --- a/src/prototype.js +++ b/src/prototype.js @@ -1,5 +1,11 @@ -<%= include 'HEADER' %> - +/* Prototype JavaScript framework, version <%= PROTOTYPE_VERSION %> + * (c) 2005-2009 Sam Stephenson + * + * Prototype is freely distributable under the terms of an MIT-style license. + * For details, see the Prototype web site: http://www.prototypejs.org/ + * + *--------------------------------------------------------------------------*/ + var Prototype = { Version: '<%= PROTOTYPE_VERSION %>', @@ -47,55 +53,8 @@ var Prototype = { if (Prototype.Browser.MobileSafari) Prototype.BrowserFeatures.SpecificElementExtensions = false; -var Abstract = { }; +//= require "lang" +//= require "ajax" +//= require "dom" -/** - * == lang == - * Language extensions. -**/ - -/** section: lang - * Try -**/ - -/** - * Try.these(function...) -> ? - * - function (Function): A function that may throw an exception. - * Accepts an arbitrary number of functions and returns the result of the - * first one that doesn't throw an error. - **/ -var Try = { - these: function() { - var returnValue; - - for (var i = 0, length = arguments.length; i < length; i++) { - var lambda = arguments[i]; - try { - returnValue = lambda(); - break; - } catch (e) { } - } - - return returnValue; - } -}; - -<%= include 'lang/class.js', 'lang/object.js', 'lang/function.js' %> - -<%= include 'lang/date.js', 'lang/regexp.js', 'lang/periodical_executer.js' %> - -<%= include 'lang/string.js', 'lang/template.js' %> - -<%= include 'lang/enumerable.js', 'lang/array.js', 'lang/hash.js' %> - -<%= include 'lang/number.js', 'lang/range.js' %> - -<%= include 'ajax/ajax.js', 'ajax/responders.js', 'ajax/base.js', 'ajax/request.js', 'ajax/response.js' %> - -<%= include 'ajax/updater.js', 'ajax/periodical_updater.js' %> - -<%= include 'dom/dom.js', 'dom/selector.js', 'dom/form.js', 'dom/event.js' %> - -<%= include 'deprecated.js' %> - -Element.addMethods(); +//= require "deprecated" diff --git a/vendor/sprockets b/vendor/sprockets index bf47292..05108e6 160000 --- a/vendor/sprockets +++ b/vendor/sprockets @@ -1 +1 @@ -Subproject commit bf472927407df4318705259ef1790718fc96eddc +Subproject commit 05108e6ca76352b8954b066cf041865415fd6bf9