Permalink
Browse files

Refactored javascript and css manifest tasks into two steps - one to …

…create transforms that build a loadable file and another that combines them. Also broke the manifest_spec into several smaller files that are easier to digest
  • Loading branch information...
1 parent fc35d33 commit 332c3abe520002fa05ba3d9a923b4cb61bd57899 Charles Jolley committed Jan 17, 2009
View
12 Buildfile
@@ -35,7 +35,11 @@ mode :all do
:load_debug => false,
# Do not build tests.
- :load_tests => false
+ :load_tests => false,
+
+ # Generate a combined javascript and stylesheet
+ :combine_javascript => true,
+ :combine_stylesheet => true
end
@@ -45,7 +49,11 @@ mode :debug do
# in debug mode, load fixtures and debug code
:load_fixtures => true,
:load_debug => true,
- :load_tests => true
+ :load_tests => true,
+
+ # Do not combine javascript and stylesheet
+ :combine_javascript => false,
+ :combine_stylesheet => false
end
View
93 buildtasks/manifest.rake
@@ -86,13 +86,14 @@ namespace :manifest do
# Is a localized resource!
if entry.filename =~ /^([^\/]+)\.lproj\/(.+)$/
entry.language = (SC::Target::LONG_LANGUAGE_MAP[$1.to_s.downcase.to_sym]) || $1.to_sym
- entry.filename = $2
entry.localized = true
# remove .lproj dir from build paths as well..
lang_dir = "#{$1}.lproj/"
- entry.build_path = entry.build_path.sub(lang_dir,'')
- entry.url = entry.url.sub(lang_dir,'')
+ sub_str = (entry.ext == 'js') ? 'lproj/' : ''
+ entry.filename = entry.filename.sub(lang_dir, sub_str)
+ entry.build_path = entry.build_path.sub(lang_dir, sub_str)
+ entry.url = entry.url.sub(lang_dir, sub_str)
# if this is part of the current language, always include...
# hide any preferred_language entry...
@@ -123,7 +124,7 @@ namespace :manifest do
namespace :prepare_build_tasks do
desc "main entrypoint for preparing all build tasks. This should invoke all needed tasks"
- task :all => %w(tests javascript css html image sass)
+ task :all => %w(tests javascript css html image sass combine)
desc "executes prerequisites needed before one of the subtasks can be invoked. All subtasks that have this as a prereq"
task :setup => %w(manifest:catalog manifest:hide_buildfiles manifest:localize)
@@ -155,63 +156,85 @@ namespace :manifest do
desc "scans for javascript files, annotates them and prepares combined entries for each output target"
task :javascript => :setup do
- # select all entries relevant entries
+ # select all original entries with with ext of css
entries = MANIFEST.entries.select do |e|
- (e.entry_type == :javascript) || (e.entry_type.nil? && e.ext == 'js')
+ e.original? && e.ext == 'js'
end
- # tag entry with build directives and sort by resource
- entries_by_resource = {}
+ # add transform & tag with build directives.
entries.each do |entry|
- entry.entry_type = :javascript
- entry.resource = 'javascript'
+ entry = MANIFEST.add_transform entry,
+ :build_task => 'build:javascript',
+ :resource => 'javascript',
+ :entry_type => :javascript
entry.discover_build_directives!
- (entries_by_resource[entry.resource] ||= []) << entry
end
- # Now, build combined entry for each resource
- entries_by_resource.each do |resource_name, entries|
- MANIFEST.add_composite resource_name.ext('js'),
- :build_task => 'build:javascript',
- :source_entries => entries
- end
end
-
- desc "scans for css files, annotates them and prepares combined entries for each output target"
+
+ desc "scans for css files, creates a transform and annotates them"
task :css => :setup do
- # select all entries with an entry_type of :css or with ext of css
+
+ # select all original entries with with ext of css
entries = MANIFEST.entries.select do |e|
- (e.entry_type == :css) || (e.entry_type.nil? && e.ext == 'css')
+ e.original? && e.ext == 'css'
end
- # tag entry with build directives and sort by resource
- entries_by_resource = {}
+ # add transform & tag with build directives.
entries.each do |entry|
- entry.entry_type = :css
- entry.resource = 'stylesheet'
+ entry = MANIFEST.add_transform entry,
+ :build_task => 'build:css',
+ :resource => 'stylesheet',
+ :entry_type => :css
entry.discover_build_directives!
- (entries_by_resource[entry.resource] ||= []) << entry
end
-
- # Now, build combined entry for each resource
- entries_by_resource.each do |resource_name, entries|
+ end
+
+ desc "generates combined entries for javascript and css"
+ task :combine => %w(setup css javascript sass) do
+
+ # sort entries...
+ css_entries = {}
+ javascript_entries = {}
+ MANIFEST.entries.each do |entry|
+ case entry.entry_type
+ when :css
+ (css_entries[entry.resource] ||= []) << entry
+ when :javascript
+ (javascript_entries[entry.resource] ||= []) << entry
+ end
+ end
+
+ # build combined CSS entry
+ css_entries.each do |resource_name, entries|
MANIFEST.add_composite resource_name.ext('css'),
- :build_task => 'build:css',
- :source_entries => entries
+ :build_task => 'build:combine:css',
+ :source_entries => entries,
+ :hide_entries => CONFIG.combine_stylesheet
end
+
+ # build combined JS entry
+ javascript_entries.each do |resource_name, entries|
+ MANIFEST.add_composite resource_name.ext('js'),
+ :build_task => 'build:combine:javascript',
+ :source_entries => entries,
+ :hide_entries => CONFIG.combine_javascript
+ end
+
end
desc "create a builder task for all sass files to create css files"
task :sass => :setup do
MANIFEST.entries.each do |entry|
next unless entry.ext == "sass"
- MANIFEST.add_transform(entry,
+ MANIFEST.add_transform entry,
:build_task => 'build:sass',
:entry_type => :css,
- :ext => 'css')
+ :ext => 'css',
+ :resource => 'stylesheet',
+ :requires => []
end
end
- task :css => :sass # IMPORTANT! to ensure sass files are rolled into css
desc "find all html-generating files, annotate and combine them"
task :html => :setup do
@@ -239,7 +262,7 @@ namespace :manifest do
# use a custom scan method since discover_build_directives! is too
# general...
- entry. scan_source(/<%\s*sc_resource\(?\s*['"](.+)['"]\s*\)?/) do |m|
+ entry.scan_source(/<%\s*sc_resource\(?\s*['"](.+)['"]\s*\)?/) do |m|
entry.resource = m[0].ext ''
end
(entries_by_resource[entry.resource] ||= []) << entry
View
13 lib/sproutcore/models/manifest.rb
@@ -128,14 +128,18 @@ def add_entry(filename, opts = {})
end
# Creates a composite entry with the passed filename. Expects you to
- # a source_entries option. This automatically hides the source entries.
+ # a source_entries option. This automatically hides the source entries
+ # unless you pass the :hide_entries => false option.
def add_composite(filename, opts = {})
+ should_hide_entries = opts.delete(:hide_entries)
+ should_hide_entries = true if should_hide_entries.nil?
+
opts[:filename] = filename
opts[:source_entries] ||= []
opts[:composite] = true
@entries << (ret = ManifestEntry.new(self, opts)).prepare!
- ret.source_entries.each { |entry| entry.hide! }
+ ret.source_entries.each { |entry| entry.hide! } if should_hide_entries
return ret
end
@@ -170,6 +174,7 @@ def add_transform(entry, opts ={})
opts.source_entry = entry
opts.source_entries = [entry]
opts.composite = true
+ opts.transform = true # make .transform? = true
# Normalize to new extension if provided. else copy ext from entry...
if opts.ext
@@ -201,7 +206,9 @@ def add_transform(entry, opts ={})
# === Returns
# the manifest entry
def entry_for(filename, opts = {})
- entries(opts).find { |entry| entry.filename == filename }
+ entries(:hidden => opts[:hidden]).find do |entry|
+ (entry.filename == filename) && entry.has_options?(opts)
+ end
end
# Finds a unique staging path starting with the root proposed staging
View
19 lib/sproutcore/models/manifest_entry.rb
@@ -88,22 +88,6 @@ def composite?; self[:composite]; end
# Marks the entry as composite. Returns self
def composite!; self[:composite] = true; self; end
- # Returns the source_path for the entry. If the entry is composite,
- # returns the first entry's staging path.
- def source_path
- composite? ? self.source_paths.first : self[:source_path]
- end
-
- # Returns all source_paths for the entry. If the entry is composite,
- # returns the staging paths for the entries. If the entriy is not
- # composite, uses the source_paths setting or the source_path setting
- def source_paths
- composite? ? self.source_entries.map { |x| x.staging_path } : (self[:source_paths] || [self[:source_path]].compact)
- end
-
- # Only used if the entry is marked as a composite
- def source_entries; self[:source_entries] || []; end
-
# The owner manifest
attr_accessor :manifest
@@ -142,7 +126,8 @@ def scan_source(regexp, &block)
#
def discover_build_directives!
self.requires = []
- scan_source(BUILD_DIRECTIVES_REGEX) do |matches|
+ entry = self.transform? ? self.source_entry : self
+ entry.scan_source(BUILD_DIRECTIVES_REGEX) do |matches|
# strip off any file ext
filename = matches[2].ext ''
case matches[0]
View
29 spec/buildtasks/build/css_spec.rb
@@ -10,24 +10,15 @@
@task_name = 'build:css'
end
- it "should concatenate the input css files according to their require order"
-
- describe "remove compiler directives" do
- it "removes sc_require() statments"
- it "removes require() statements"
- it "removes sc_resurce() statements"
-
- it "does not remove directives inside of comments"
-
- it "does not remove directives inside of quoted strings"
- end
-
- it "substitutes static_url() and sc_static_url() directives"
-
- it "minifies the css if CONFIG.minify_css is true"
-
- it "minifies the css if CONFIG.minify is true"
-
- it "labels the start of each CSS file in concatenated result"
+ # describe "wraps compiler directives in comments" do
+ # it "sc_require()"
+ #
+ # it "require()"
+ # it "sc_resource()"
+ #
+ # it "does not remove directives inside of comments"
+ # end
+ #
+ # it "substitutes static_url() and sc_static_url() directives"
end
View
16 spec/buildtasks/build/html_spec.rb
@@ -10,12 +10,12 @@
@task_name = 'build:html'
end
- it "sets up a shared HtmlContext and invokes the render_task for each entry"
-
- it "finally renders the layout specified in MANIFEST.layout_path"
-
- it "substitutes static_url() directives"
-
- it "supports common text helpers in context"
-
+ # it "sets up a shared HtmlContext and invokes the render_task for each entry"
+ #
+ # it "finally renders the layout specified in MANIFEST.layout_path"
+ #
+ # it "substitutes static_url() directives"
+ #
+ # it "supports common text helpers in context"
+ #
end
View
22 spec/buildtasks/build/javascript_spec.rb
@@ -10,16 +10,16 @@
@task_name = 'build:javascript'
end
- it "should concatenate the input JS files according to their require order"
-
- it "substitutes static_url() and sc_static_url() directives"
-
- it "substitutes sc_super() directives"
-
- it "minifies the Javascript if CONFIG.minify_javascript is true"
-
- it "minifies the Javascript if CONFIG.minify is true"
-
- it "labels the start of each JS file in concatenated result (before minify)"
+ # it "should concatenate the input JS files according to their require order"
+ #
+ # it "substitutes static_url() and sc_static_url() directives"
+ #
+ # it "substitutes sc_super() directives"
+ #
+ # it "minifies the Javascript if CONFIG.minify_javascript is true"
+ #
+ # it "minifies the Javascript if CONFIG.minify is true"
+ #
+ # it "labels the start of each JS file in concatenated result (before minify)"
end
View
48 spec/buildtasks/manifest/catalog_spec.rb
@@ -0,0 +1,48 @@
+require File.join(File.dirname(__FILE__), 'spec_helper')
+
+describe "manifest:catalog" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task
+ @manifest.prepare! # this should be run first...
+ super('manifest:catalog')
+ end
+
+ it "create an entry for each item in the target regardless of language with the relative path as filename" do
+ run_task
+
+ # collect filenames from target dir...
+ filenames = Dir.glob(File.join(@target.source_root, '**','*'))
+ filenames.reject! { |f| File.directory?(f) }
+ filenames.map! { |f| f.sub(@target.source_root + '/', '') }
+ filenames.reject! { |f| f =~ /^(apps|frameworks)/ }
+
+ entries = @manifest.entries.dup # get entries to test...
+ filenames.each do |filename|
+ entry = entries.find { |e| e.filename == filename }
+ if entry.nil?
+ nil.should == filename # oops! not found...
+ else
+ entry.filename.should == filename
+ entry.build_task.should == 'build:copy'
+ entry.build_path.should == File.join(@manifest.build_root, filename)
+ entry.staging_path.should == File.join(@manifest.source_root, filename)
+ entry.source_path.should == entry.staging_path
+ entry.url.should == [@manifest.url_root, filename] * '/'
+ entry.should_not be_hidden
+ entry.original?.should be_true # mark as original entry
+ end
+
+ (entry.nil? ? nil : entry.filename).should == filename
+ entries.delete entry
+ end
+ entries.size.should == 0
+ end
+
+end
View
101 spec/buildtasks/manifest/hide_buildfiles_spec.rb
@@ -0,0 +1,101 @@
+require File.join(File.dirname(__FILE__), 'spec_helper')
+
+describe "manifest:hide_buildfiles" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+
+ def run_task
+ @manifest.prepare!
+ super('manifest:hide_buildfiles')
+ end
+
+ it "should run manifest:catalog first" do
+ should_run('manifest:catalog') { run_task }
+ end
+
+ it "should hide any Buildfile, sc-config, or sc-config.rb" do
+ run_task
+ entry_for('Buildfile').hidden?.should be_true
+ end
+
+ it "should hide any non .js file outside of .lproj, test, fixture, & debug dirs" do
+ run_task
+ entry_for('README').hidden?.should be_true
+ entry_for('lib/index.html').hidden?.should be_true
+
+ entry_for('tests/sample.rhtml').hidden?.should be_false
+ entry_for('english.lproj/demo.html').hidden?.should be_false
+ entry_for('fixtures/sample-json-fixture.json').hidden?.should be_false
+ entry_for('debug/debug-resource.html').hidden?.should be_false
+ end
+
+ it "should NOT hide non-js files inslide lproj dirs" do
+ run_task
+ entry = entry_for('english.lproj/demo.html')
+ entry.should_not be_hidden
+ end
+
+ # CONFIG.load_fixtures
+ it "should hide files in /fixtures and /*.lproj/fixtures if CONFIG.load_fixtures is false" do
+ @target.config.load_fixtures = false
+ run_task
+ entry = entry_for('fixtures/sample_fixtures.js')
+ entry.should be_hidden
+ entry = entry_for('english.lproj/fixtures/sample_fixtures-loc.js')
+ entry.should be_hidden
+ end
+
+ it "should NOT hide files in /fixtures and /*.lproj/fixtures if CONFIG.load_fixtures is true" do
+ @target.config.load_fixtures = true
+ run_task
+ entry = entry_for('fixtures/sample_fixtures.js')
+ entry.should_not be_hidden
+ entry = entry_for('english.lproj/fixtures/sample_fixtures-loc.js')
+ entry.should_not be_hidden
+ end
+
+ # CONFIG.load_debug
+ it "should hide files in /debug and /*.lproj/debug if CONFIG.load_debug is false" do
+ @target.config.load_debug = false
+ run_task
+ entry = entry_for('debug/sample_debug.js')
+ entry.should be_hidden
+ entry = entry_for('english.lproj/debug/sample_debug-loc.js')
+ entry.should be_hidden
+ end
+
+ it "should NOT hide files in /debug and /*.lproj/debug if CONFIG.load_fixtures is true" do
+ @target.config.load_debug = true
+ run_task
+ entry = entry_for('debug/sample_debug.js')
+ entry.should_not be_hidden
+ entry = entry_for('english.lproj/debug/sample_debug-loc.js')
+ entry.should_not be_hidden
+ end
+
+ # CONFIG.load_tests
+ it "should hide files in /tests and /*.lproj/tests if CONFIG.load_tests is false" do
+ @target.config.load_tests = false
+ run_task
+ entry = entry_for('tests/sample.js')
+ entry.should be_hidden
+ entry = entry_for('english.lproj/tests/sample-loc.js')
+ entry.should be_hidden
+ end
+
+ it "should NOT hide files in /tests and /*.lproj/tests if CONFIG.load_tests is true" do
+ @target.config.load_tests = true
+ run_task
+ entry = entry_for('tests/sample.js')
+ entry.should_not be_hidden
+ entry = entry_for('english.lproj/tests/sample-loc.js')
+ entry.should_not be_hidden
+ end
+
+end
View
97 spec/buildtasks/manifest/localize_spec.rb
@@ -0,0 +1,97 @@
+require File.join(File.dirname(__FILE__), 'spec_helper')
+
+describe "manifest:localize" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task
+ @manifest.prepare!
+ super('manifest:localize')
+ end
+
+ it "should run manifest:catalog && hide_buildfiles as prereq" do
+ should_run('manifest:catalog') { run_task }
+ should_run('manifest:hide_buildfiles') { run_task }
+ end
+
+ it "should not alter non-localized files" do
+ run_task
+ entry = entry_for('core.js')
+ entry.should_not be_nil
+ entry.should_not be_hidden
+ end
+
+ it "should mark all entries with localized? = true" do
+ run_task
+ @manifest.entries.each do |entry|
+ if entry.source_path =~ /\.lproj/
+ entry.localized?.should be_true
+ else
+ entry.localized?.should_not be_true
+ end
+ end
+ end
+
+ it "should remove foo.lproj from filename, build_path, and url of localized except for css and js files, which get 'lproj' instead" do
+ run_task
+ @manifest.entries.each do |entry|
+ next unless entry.localized?
+ new_filename = entry.source_path.match(/\.lproj\/(.+)$/).to_a[1]
+ if entry.ext == 'js'
+ new_filename = "lproj/#{new_filename}"
+ end
+
+ entry.filename.should eql(new_filename)
+ entry.build_path = File.join(@manifest.build_root, new_filename.split('/'))
+ entry.url = [@manifest.url_root, new_filename.split('/')].flatten.join('/')
+ end
+ end
+
+ it "should assign language to localized entries" do
+ run_task
+ # we just test this by spot checking to make sure any entry in the
+ # french.lproj actually has a french language code assigned...
+ @manifest.entries.each do |entry|
+ next unless entry.localize? && (entry.source_path =~ /french\.lproj/)
+ entry.language.should eql(:fr)
+ end
+ end
+
+ it "should not hide resources in current language" do
+ run_task
+ entry = entry_for('lproj/french-resource.js')
+ entry.localized?.should be_true
+ entry.should_not be_hidden
+ entry.language.should eql(:fr)
+ end
+
+ it "should not hide resource in preferred language that are not also found in current language" do
+ run_task
+ entry = entry_for('demo.html')
+ entry.localized?.should be_true
+ entry.language.should eql(:en)
+ entry.should_not be_hidden
+ end
+
+ it "should prefer resource in current language over those in preferred language" do
+ run_task
+ # a 'strings.js' is defined in english.lproj, french.lproj, & german
+ # this should use the french version since that one is current
+ entry = @manifest.entry_for('lproj/strings.js')
+ entry.localized?.should be_true
+ entry.should_not be_hidden
+ entry.language.should eql(:fr)
+ end
+
+ it "should hide resources in languages not part of current language or preferred language" do
+ run_task
+ entry = entry_for('lproj/german-resource.js')
+ entry.should be_hidden
+ end
+
+end
View
146 spec/buildtasks/manifest/prepare_build_tasks/combine_spec.rb
@@ -0,0 +1,146 @@
+require File.join(File.dirname(__FILE__), %w(.. spec_helper))
+
+# Creates combined entries for javascript & css
+describe "manifest:prepare_build_tasks:combine" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task
+ @manifest.prepare!
+ super('manifest:prepare_build_tasks:combine')
+ end
+
+ it "should run setup, javascript, css, & sass as prereq" do
+ %w(setup javascript css sass).each do |task_name|
+ should_run("manifest:prepare_build_tasks:#{task_name}") { run_task }
+ end
+ end
+
+ #######################################
+ # stylesheet.css support
+ #
+ describe "whem CONFIG.combine_stylesheet = true" do
+
+ before do
+ @config.combine_stylesheet = true
+ run_task
+ end
+
+ it "creates a combined stylesheet entry for each resource named in files" do
+ # spot check...
+ entry = entry_for 'stylesheet.css'
+ expected = entry_for('has_require.css', :entry_type => :css)
+ entry.source_entries.should include(expected)
+
+ expected = entry_for('no_require.css', :entry_type => :css)
+ entry.source_entries.should include(expected)
+
+ # Test that sass file is included...
+ expected = entry_for('demo2.css', :entry_type => :css)
+ entry.source_entries.should include(expected)
+
+ entry = entry_for 'bar.css'
+ expected = entry_for('sc_resource.css', :entry_type => :css)
+ entry.source_entries.should include(expected)
+ end
+
+ it "entries have a build_task = build:combine:css" do
+ entry_for('stylesheet.css').build_task.should == 'build:combine:css'
+ entry_for('bar.css').build_task.should == 'build:combine:css'
+ end
+
+ it "hides source entries" do
+ %w(stylesheet.css bar.css).each do |filename|
+ entry_for(filename).source_entries.each do |entry|
+ entry.should be_hidden
+ end
+ end
+ end
+
+ end
+
+ describe "when CONFIG.combine_stylesheet = false" do
+
+ before do
+ @config.combine_stylesheet = false
+ run_task
+ end
+
+ it "still creates combined CSS entry" do
+ entry = entry_for('stylesheet.css')
+ entry.should_not be_nil
+ end
+
+ it "does not hide source CSS entries" do
+ entry = entry_for('stylesheet.css')
+ entry.should_not be_nil
+ entry.source_entries.each { |entry| entry.should_not be_hidden }
+ end
+ end
+
+ #######################################
+ # javascript.js support
+ #
+
+ describe "whem CONFIG.combine_javascript = true" do
+
+ before do
+ @config.combine_javascript = true
+ run_task
+ end
+
+ it "creates a combined JS entry for each resource named in files" do
+ # spot check...
+ entry = entry_for 'javascript.js'
+ expected = entry_for('has_require.js', :entry_type => :javascript)
+ entry.source_entries.should include(expected)
+
+ expected = entry_for('no_require.js', :entry_type => :javascript)
+ entry.source_entries.should include(expected)
+
+ entry = entry_for 'bar.js'
+ expected = entry_for('sc_resource.js', :entry_type => :javascript)
+ entry.source_entries.should include(expected)
+ end
+
+ it "entries have a build_task = build:combine:javascript" do
+ %w(javascript.js bar.js).each do |filename|
+ entry_for(filename).build_task.should == 'build:combine:javascript'
+ end
+ end
+
+ it "hides source entries" do
+ %w(javascript.js bar.js).each do |filename|
+ entry_for(filename).source_entries.each do |entry|
+ entry.should be_hidden
+ end
+ end
+ end
+
+ end
+
+ describe "when CONFIG.combine_javascript = false" do
+
+ before do
+ @config.combine_javascript = false
+ run_task
+ end
+
+ it "still creates combined JS entry" do
+ entry = entry_for('javascript.js')
+ entry.should_not be_nil
+ end
+
+ it "does not hide source JS entries" do
+ entry = entry_for('javascript.js')
+ entry.should_not be_nil
+ entry.source_entries.each { |entry| entry.should_not be_hidden }
+ end
+ end
+
+end
View
75 spec/buildtasks/manifest/prepare_build_tasks/css_spec.rb
@@ -0,0 +1,75 @@
+require File.join(File.dirname(__FILE__), %w(.. spec_helper))
+
+# This task prepares a single CSS entry for every untagged source entry.
+describe "manifest:prepare_build_tasks:css" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task
+ @manifest.prepare!
+ super('manifest:prepare_build_tasks:css')
+ end
+
+ it "should run manifest:prepare_build_tasks:setup as prereq" do
+ should_run('manifest:prepare_build_tasks:setup') { run_task }
+ end
+
+ it "creates a transform entry for each css entry" do
+ run_task
+
+ # find all original CSS entries...
+ originals = @manifest.entries(:hidden => true).select do |entry|
+ entry.original? && entry.ext == 'css'
+ end
+ originals.size.should > 0 # precondition
+
+ # transformed entries
+ entries = @manifest.entries.select { |e| e.entry_type == :css }
+ entries.size.should == originals.size #precondition
+
+ # one transformed entry should exist for each original entry.
+ entries.each do |entry|
+ entry.should be_transform
+ entry.source_entry.should_not be_nil
+ originals.should include(entry.source_entry)
+ originals.delete(entry.source_entry) # so as not to allow doubles
+ end
+ originals.size.should == 0
+ end
+
+ describe "supports require() and sc_require() statements" do
+
+ it "adds a entry.requires property with empty array of no requires are specified in file" do
+ run_task
+ entry = @manifest.entry_for('no_require.css')
+ entry.requires.should == []
+ end
+
+ it "searches files for require() & sc_requires() statements and adds them to entry.requires array -- (also should ignore any ext)" do
+ run_task
+ entry = @manifest.entry_for('has_require.css')
+ entry.requires.sort.should == ['demo2', 'no_require']
+ end
+
+ end
+
+ describe "supports sc_resource() statement" do
+ it "sets entry.resource = 'stylesheet' if no sc_resource statement is found in files" do
+ run_task
+ entry = @manifest.entry_for('no_require.css')
+ entry.resource.should == 'stylesheet'
+ end
+
+ it "searches files for sc_resource() statement and stores last value in entry.resource property" do
+ run_task
+ entry = @manifest.entry_for 'sc_resource.css'
+ entry.resource.should == 'bar'
+ end
+ end
+
+end
View
108 spec/buildtasks/manifest/prepare_build_tasks/html_spec.rb
@@ -0,0 +1,108 @@
+require File.join(File.dirname(__FILE__), %w(.. spec_helper))
+
+describe "manifest:prepare_build_tasks:html" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task
+ @manifest.prepare!
+ super('manifest:prepare_build_tasks:html')
+ end
+
+ it "should run manifest:prepare_build_tasks:setup as prereq" do
+ should_run('manifest:prepare_build_tasks:setup') { run_task }
+ end
+
+ describe "supports sc_resource() statement" do
+ it "sets entry.resource = 'index' if no sc_resource statement is found in files" do
+ run_task
+ entry = entry_for('no_sc_resource.rhtml')
+ entry.resource.should == 'index'
+ end
+
+ it "searches files for sc_resource() statement and stores last value in entry.resource property" do
+ run_task
+ entry = entry_for 'sc_resource.rhtml'
+ entry.resource.should == 'bar'
+ end
+ end
+
+ describe "annotates entries with render_task" do
+
+ before do
+ run_task
+ end
+
+ it "file.erb => render:erubis" do
+ expected = entry_for('file_extension_test.html.erb')
+ expected.render_task.should == "render:erubis"
+ end
+
+ it "file.haml => render:haml" do
+ expected = entry_for('file_extension_test.haml')
+ expected.render_task.should == "render:haml"
+ end
+
+ it "file.rhtml => render:erubis" do
+ expected = entry_for('file_extension_test.rhtml')
+ expected.render_task.should == "render:erubis"
+ end
+
+ end
+
+ describe "combines html entries into one output file per resource" do
+
+ before do
+ run_task
+ @index_entry = @manifest.entry_for 'index.html'
+ @bar_entry = @manifest.entry_for('bar.html')
+ end
+
+ it "should be composite entries" do
+ @index_entry.should be_composite
+ @bar_entry.should be_composite
+ end
+
+ it "should include any files ending in .rhtml" do
+ expected = entry_for('file_extension_test.rhtml')
+ @index_entry.source_entries.should include(expected)
+ end
+
+ it "should include any files ending in .erb" do
+ expected = entry_for('file_extension_test.html.erb')
+ @index_entry.source_entries.should include(expected)
+ end
+
+ it "should include any files ending in .haml" do
+ expected = entry_for('file_extension_test.haml')
+ @index_entry.source_entries.should include(expected)
+ end
+
+ it "creates a combined index entry for each resource named in files" do
+ # spot check...
+ @index_entry.source_entries.should include(entry_for('no_sc_resource.rhtml'))
+
+ @bar_entry.source_entries.should include(entry_for('sc_resource.rhtml'))
+ end
+
+ it "entries have a build_task = build:html" do
+ @index_entry.build_task.should == 'build:html'
+ @bar_entry.build_task.should == 'build:html'
+ end
+
+ it "hides source entries" do
+ [@index_entry, @bar_entry].each do |entry|
+ entry.source_entries.each do |source_entry|
+ source_entry.should be_hidden
+ end
+ end
+ end
+
+ end
+
+end
View
53 spec/buildtasks/manifest/prepare_build_tasks/javascript_spec.rb
@@ -0,0 +1,53 @@
+require File.join(File.dirname(__FILE__), %w(.. spec_helper))
+
+describe "manifest:prepare_build_tasks:javascript" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task
+ @manifest.prepare!
+ super('manifest:prepare_build_tasks:javascript')
+ end
+
+ it "should run manifest:prepare_build_tasks:setup as prereq" do
+ should_run('manifest:prepare_build_tasks:setup') { run_task }
+ end
+
+ describe "supports require() and sc_require() statements" do
+
+ it "adds a entry.requires property to entrys with empty array of no requires are specified in file" do
+ run_task
+ entry = entry_for('no_require.js')
+ entry.requires.should == []
+ end
+
+ it "searches files for require() & sc_requires() statements and adds them to entry.requires array -- (also should ignore any ext)" do
+ run_task
+ entry = entry_for('has_require.js')
+ entry.requires.sort.should == ['demo2', 'no_require']
+ end
+
+ end
+
+ describe "supports sc_resource() statement" do
+ it "sets entry.resource = 'stylesheet' if no sc_resource statement is found in files" do
+ run_task
+ entry = entry_for('no_require.js')
+ entry.resource.should == 'javascript'
+ end
+
+ it "searches files for sc_resource() statement and stores last value in entry.resource property" do
+ run_task
+ entry =entry_for 'sc_resource.js'
+ entry.resource.should == 'bar'
+ end
+ end
+
+
+
+end
View
90 spec/buildtasks/manifest/prepare_build_tasks/sass_spec.rb
@@ -0,0 +1,90 @@
+require File.join(File.dirname(__FILE__), %w(.. spec_helper))
+
+describe "manifest:prepare_build_tasks:sass" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task
+ @manifest.prepare!
+ super('manifest:prepare_build_tasks:sass')
+ end
+
+ it "should run manifest:prepare_build_tasks:setup as prereq" do
+ should_run('manifest:prepare_build_tasks:setup') { run_task }
+ end
+
+ it "should create a transform entry (with entry_type == :css) for every sass entry" do
+ run_task
+ entries = @manifest.entries(:hidden => true)
+
+ # find all entries referencing original source...
+ source_entries = entries.reject do |entry|
+ !(entry.original? && entry.filename =~ /\.sass$/)
+ end
+ source_entries.size.should > 0 # precondition
+
+ # final all test transform entries.
+ test_entries = entries.reject { |e| e.entry_type != :css }
+ test_entries.size.should eql(source_entries.size) # 1 for each entry?
+ test_entries.each do |entry|
+ source_entries.should include(entry.source_entry)
+ source_entries.delete(entry.source_entry) # avoid double counting
+ end
+
+ # none should be left...
+ source_entries.size.should == 0
+ end
+
+ # check the format of each entry...
+ describe "sass -> css transform entry" do
+
+ before do
+ run_task
+ @entries = @manifest.entries.reject do |e|
+ !(e.entry_type == :css && e.source_entry.filename =~ /\.sass$/)
+ end
+ end
+
+ it "changes the filename + build_path + url ext to .css" do
+ @entries.each do |entry|
+ File.extname(entry.filename).should == '.css'
+ File.extname(entry.build_path).should == '.css'
+ File.extname(entry.url).should == '.css'
+ end
+ end
+
+ it "assigns a build_task of build:sass" do
+ @entries.each do |entry|
+ entry.build_task.to_s.should == 'build:sass'
+ end
+ end
+
+ it "hides the source entry" do
+ @entries.each do |entry|
+ entry.source_entry.should be_hidden
+ end
+ end
+
+ #### NOTE: Currently build directives such as sc_require() and
+ #### sc_resource() are not supported in sass files. These rules test that
+ #### some basics are filled in anyway. Feel free to add support for said
+ #### directive processing if you need it and change these tests! :-)
+ it "sets the entry.resource => stylesheet" do
+ @entries.each do |entry|
+ entry.resource.should == 'stylesheet'
+ end
+ end
+
+ it "sets the entry.requires => []" do
+ @entries.each do |entry|
+ entry.requires.should == []
+ end
+ end
+
+ end # describe sass -> css transform entry
+end
View
101 spec/buildtasks/manifest/prepare_build_tasks/tests_spec.rb
@@ -0,0 +1,101 @@
+require File.join(File.dirname(__FILE__), %w(.. spec_helper))
+
+describe "manifest:prepare_build_tasks:tests" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task(load_tests=true)
+ @manifest.prepare!
+ @target.config.load_tests = load_tests # force...
+ super('manifest:prepare_build_tasks:tests')
+ end
+
+ it "should run manifest:localize & manifest:catalog as prereq" do
+ should_run('manifest:catalog') { run_task }
+ should_run('manifest:localize') { run_task }
+ end
+
+ it "should create a transform entry (with entry_type == :test) for every test entry" do
+ run_task
+ entries = @manifest.entries(:hidden => true)
+
+ # find all entries referencing original source...
+ source_entries = entries.reject do |entry|
+ !(entry.original? && entry.filename =~ /^tests\//)
+ end
+ source_entries.size.should > 0 # precondition
+
+ # final all test transform entries.
+ test_entries = entries.reject { |e| e.entry_type != :test }
+ test_entries.size.should eql(source_entries.size) # 1 for each entry?
+ test_entries.each do |entry|
+ source_entries.should include(entry.source_entry)
+ source_entries.delete(entry.source_entry) # avoid double counting
+ end
+
+ # none should be left...
+ source_entries.size.should == 0
+ end
+
+ # check the format of each entry...
+ describe "transform entry" do
+
+ before do
+ run_task
+ @entries = @manifest.entries.reject { |e| e.entry_type != :test }
+ end
+
+ it "changes the filename + build_path + url ext to .html" do
+ @entries.each do |entry|
+ File.extname(entry.filename).should == '.html'
+ File.extname(entry.build_path).should == '.html'
+ File.extname(entry.url).should == '.html'
+ end
+ end
+
+ it "assigns a build_task of build:test:EXTNAME (from source_entry)" do
+ @entries.each do |entry|
+ extname = File.extname(entry.source_entry.filename)[1..-1]
+ entry.build_task.to_s.should == "build:test:#{extname.downcase}"
+ end
+ end
+
+ end
+
+ it "should create a composite entry to generate a -index.json with test entries as source" do
+ run_task
+ entry = @manifest.entry_for('tests/-index.json')
+
+ entry.should_not be_nil
+ entry.entry_type.should == :resource
+ entry.build_task.to_s.should == 'build:test:index.json'
+
+ expected = @manifest.entries.reject { |e| e.entry_type != :test }
+ entry.source_entries.size.should eql(expected.size)
+ entry.source_entries.each do |entry|
+ expected.should include(entry)
+ expected.delete(entry) # avoid double counting
+ end
+ expected.size.should == 0 # should have an empty size...
+ end
+
+ it "should not hide -index.json source_entries (since they are test that need to be built)" do
+ run_task
+ entry = @manifest.entry_for('tests/-index.json')
+ entry.source_entries.each do |entry|
+ entry.should_not be_hidden
+ end
+ end
+
+ it "should not generate an -index.json entry if tests not loaded" do
+ run_task(false)
+ entry = @manifest.entry_for('tests/-index.json')
+ entry.should be_nil
+ end
+
+end
View
43 spec/buildtasks/manifest/prepare_spec.rb
@@ -0,0 +1,43 @@
+require File.join(File.dirname(__FILE__), 'spec_helper')
+
+describe "manifest:prepare" do
+
+ include SC::SpecHelpers
+ include SC::ManifestSpecHelpers
+
+ before do
+ std_before
+ end
+
+ def run_task; super('manifest:prepare'); end
+
+ it "sets build_root => target.build_root/language/build_number" do
+ run_task
+ expected = File.join(@target.build_root, 'fr', @target.build_number)
+ @manifest.build_root.should == expected
+ end
+
+ it "sets staging_root => staging_root/language/build_number" do
+ run_task
+ expected = File.join(@target.staging_root, 'fr', @target.build_number)
+ @manifest.staging_root.should == expected
+ end
+
+ it "sets url_root => url_root/language/build_number" do
+ run_task
+ expected = [@target.url_root, 'fr', @target.build_number] * '/'
+ @manifest.url_root.should == expected
+ end
+
+ it "sets source_root => target.source_root" do
+ run_task
+ @manifest.source_root.should == @target.source_root
+ end
+
+ it "sets index_root => index_root/language/build_number" do
+ run_task
+ expected = [@target.index_root, 'fr', @target.build_number] * '/'
+ @manifest.index_root.should == expected
+ end
+
+end
View
35 spec/buildtasks/manifest/spec_helper.rb
@@ -0,0 +1,35 @@
+require File.join(File.dirname(__FILE__), %w[.. .. spec_helper])
+
+module SC::ManifestSpecHelpers
+
+ def std_before
+ @project = fixture_project :real_world
+ @target = @project.target_for :sproutcore
+ @buildfile = @target.buildfile
+ @config = @target.config
+ @manifest = @target.manifest_for(:language => :fr)
+
+ @target.prepare! # make sure its ready for the manifest...
+ end
+
+ def run_task(task_name)
+ @buildfile.invoke task_name,
+ :manifest => @manifest,
+ :target => @target,
+ :project => @project,
+ :config => @config
+ end
+
+ def entry_for(filename, opts={})
+ @manifest.entry_for(filename, opts) || @manifest.entry_for(filename, opts.merge(:hidden => true))
+ end
+
+ # Verifies that the named task runs when the passed block is executed
+ def should_run(task_name, &block)
+ task = @buildfile.lookup(task_name)
+ first_count = task.invoke_count
+ yield if block_given?
+ task.invoke_count.should > first_count
+ end
+
+end
View
699 spec/buildtasks/manifest_spec.rb
@@ -1,699 +0,0 @@
-require File.join(File.dirname(__FILE__), %w[.. spec_helper])
-
-describe "namespace :manifest" do
-
- include SC::SpecHelpers
-
- before do
- @project = fixture_project :real_world
- @target = @project.target_for :sproutcore
- @buildfile = @target.buildfile
- @manifest = @target.manifest_for(:language => :fr)
-
- @target.prepare! # make sure its ready for the manifest...
- end
-
- def run_task(task_name)
- @buildfile.invoke task_name,
- :manifest => @manifest,
- :target => @target,
- :project => @project,
- :config => @target.config
- end
-
- def entry_for(filename)
- @manifest.entry_for filename, :hidden => true
- end
-
- # Verifies that the named task runs when the passed block is executed
- def should_run(task_name, &block)
- task = @buildfile.lookup(task_name)
- first_count = task.invoke_count
- yield if block_given?
- task.invoke_count.should > first_count
- end
-
- # Prepares some standard properties needed by the manifest
- describe "manifest:prepare" do
-
- def run_task; super('manifest:prepare'); end
-
- it "sets build_root => target.build_root/language/build_number" do
- run_task
- expected = File.join(@target.build_root, 'fr', @target.build_number)
- @manifest.build_root.should == expected
- end
-
- it "sets staging_root => staging_root/language/build_number" do
- run_task
- expected = File.join(@target.staging_root, 'fr', @target.build_number)
- @manifest.staging_root.should == expected
- end
-
- it "sets url_root => url_root/language/build_number" do
- run_task
- expected = [@target.url_root, 'fr', @target.build_number] * '/'
- @manifest.url_root.should == expected
- end
-
- it "sets source_root => target.source_root" do
- run_task
- @manifest.source_root.should == @target.source_root
- end
-
- it "sets index_root => index_root/language/build_number" do
- run_task
- expected = [@target.index_root, 'fr', @target.build_number] * '/'
- @manifest.index_root.should == expected
- end
-
- end
-
- # Adds a copyfile entry for each item in the source
- describe 'manifest:catalog' do
-
- def run_task
- @manifest.prepare! # this should be run first...
- super('manifest:catalog')
- end
-
- it "create an entry for each item in the target regardless of language with the relative path as filename" do
- run_task
-
- # collect filenames from target dir...
- filenames = Dir.glob(File.join(@target.source_root, '**','*'))
- filenames.reject! { |f| File.directory?(f) }
- filenames.map! { |f| f.sub(@target.source_root + '/', '') }
- filenames.reject! { |f| f =~ /^(apps|frameworks)/ }
-
- entries = @manifest.entries.dup # get entries to test...
- filenames.each do |filename|
- entry = entries.find { |e| e.filename == filename }
- if entry.nil?
- nil.should == filename # oops! not found...
- else
- entry.filename.should == filename
- entry.build_task.should == 'build:copy'
- entry.build_path.should == File.join(@manifest.build_root, filename)
- entry.staging_path.should == File.join(@manifest.source_root, filename)
- entry.source_path.should == entry.staging_path
- entry.url.should == [@manifest.url_root, filename] * '/'
- entry.should_not be_hidden
- entry.original?.should be_true # mark as original entry
- end
-
- (entry.nil? ? nil : entry.filename).should == filename
- entries.delete entry
- end
- entries.size.should == 0
- end
-
- end
-
- describe "manifest:hide_buildfiles" do
-
- def run_task
- @manifest.prepare!
- super('manifest:hide_buildfiles')
- end
-
- it "should run manifest:catalog first" do
- should_run('manifest:catalog') { run_task }
- end
-
- it "should hide any Buildfile, sc-config, or sc-config.rb" do
- run_task
- entry_for('Buildfile').hidden?.should be_true
- end
-
- it "should hide any non .js file outside of .lproj, test, fixture, & debug dirs" do
- run_task
- entry_for('README').hidden?.should be_true
- entry_for('lib/index.html').hidden?.should be_true
-
- entry_for('tests/sample.rhtml').hidden?.should be_false
- entry_for('english.lproj/demo.html').hidden?.should be_false
- entry_for('fixtures/sample-json-fixture.json').hidden?.should be_false
- entry_for('debug/debug-resource.html').hidden?.should be_false
- end
-
- it "should NOT hide non-js files inslide lproj dirs" do
- run_task
- entry = entry_for('english.lproj/demo.html')
- entry.should_not be_hidden
- end
-
- # CONFIG.load_fixtures
- it "should hide files in /fixtures and /*.lproj/fixtures if CONFIG.load_fixtures is false" do
- @target.config.load_fixtures = false
- run_task
- entry = entry_for('fixtures/sample_fixtures.js')
- entry.should be_hidden
- entry = entry_for('english.lproj/fixtures/sample_fixtures-loc.js')
- entry.should be_hidden
- end
-
- it "should NOT hide files in /fixtures and /*.lproj/fixtures if CONFIG.load_fixtures is true" do
- @target.config.load_fixtures = true
- run_task
- entry = entry_for('fixtures/sample_fixtures.js')
- entry.should_not be_hidden
- entry = entry_for('english.lproj/fixtures/sample_fixtures-loc.js')
- entry.should_not be_hidden
- end
-
- # CONFIG.load_debug
- it "should hide files in /debug and /*.lproj/debug if CONFIG.load_debug is false" do
- @target.config.load_debug = false
- run_task
- entry = entry_for('debug/sample_debug.js')
- entry.should be_hidden
- entry = entry_for('english.lproj/debug/sample_debug-loc.js')
- entry.should be_hidden
- end
-
- it "should NOT hide files in /debug and /*.lproj/debug if CONFIG.load_fixtures is true" do
- @target.config.load_debug = true
- run_task
- entry = entry_for('debug/sample_debug.js')
- entry.should_not be_hidden
- entry = entry_for('english.lproj/debug/sample_debug-loc.js')
- entry.should_not be_hidden
- end
-
- # CONFIG.load_tests
- it "should hide files in /tests and /*.lproj/tests if CONFIG.load_tests is false" do
- @target.config.load_tests = false
- run_task
- entry = entry_for('tests/sample.js')
- entry.should be_hidden
- entry = entry_for('english.lproj/tests/sample-loc.js')
- entry.should be_hidden
- end
-
- it "should NOT hide files in /tests and /*.lproj/tests if CONFIG.load_tests is true" do
- @target.config.load_tests = true
- run_task
- entry = entry_for('tests/sample.js')
- entry.should_not be_hidden
- entry = entry_for('english.lproj/tests/sample-loc.js')
- entry.should_not be_hidden
- end
-
- end
-
- describe "manifest:localize" do
-
- def run_task
- @manifest.prepare!
- super('manifest:localize')
- end
-
- it "should run manifest:catalog && hide_buildfiles as prereq" do
- should_run('manifest:catalog') { run_task }
- should_run('manifest:hide_buildfiles') { run_task }
- end
-
- it "should not alter non-localized files" do
- run_task
- entry = entry_for('core.js')
- entry.should_not be_nil
- entry.should_not be_hidden
- end
-
- it "should mark all entries with localized? = true" do
- run_task
- @manifest.entries.each do |entry|
- if entry.source_path =~ /\.lproj/
- entry.localized?.should be_true
- else
- entry.localized?.should_not be_true
- end
- end
- end
-
- it "should remove foo.lproj from filename, build_path, and url of localized" do
- run_task
- @manifest.entries.each do |entry|
- next unless entry.localized?
- new_filename = entry.source_path.match(/\.lproj\/(.+)$/).to_a[1]
- entry.filename.should eql(new_filename)
- entry.build_path = File.join(@manifest.build_root, new_filename.split('/'))
- entry.url = [@manifest.url_root, new_filename.split('/')].flatten.join('/')
- end
- end
-
- it "should assign language to localized entries" do
- run_task
- # we just test this by spot checking to make sure any entry in the
- # french.lproj actually has a french language code assigned...
- @manifest.entries.each do |entry|
- next unless entry.localize? && (entry.source_path =~ /french\.lproj/)
- entry.language.should eql(:fr)
- end
- end
-
- it "should not hide resources in current language" do
- run_task
- entry = entry_for('french-resource.js')
- entry.localized?.should be_true
- entry.should_not be_hidden
- entry.language.should eql(:fr)
- end
-
- it "should not hide resource in preferred language that are not also found in current language" do
- run_task
- entry = entry_for('demo.html')
- entry.localized?.should be_true
- entry.language.should eql(:en)
- entry.should_not be_hidden
- end
-
- it "should prefer resource in current language over those in preferred language" do
- run_task
- # a 'strings.js' is defined in english.lproj, french.lproj, & german
- # this should use the french version since that one is current
- entry = @manifest.entry_for('strings.js')
- entry.localized?.should be_true
- entry.should_not be_hidden
- entry.language.should eql(:fr)
- end
-
- it "should hide resources in languages not part of current language or preferred language" do
- run_task
- entry = entry_for('german-resource.js')
- entry.should be_hidden
- end
-
- end
-
- describe "manifest:prepare_build_tasks:tests" do
-
- def run_task(load_tests=true)
- @manifest.prepare!
- @target.config.load_tests = load_tests # force...
- super('manifest:prepare_build_tasks:tests')
- end
-
- it "should run manifest:localize & manifest:catalog as prereq" do
- should_run('manifest:catalog') { run_task }
- should_run('manifest:localize') { run_task }
- end
-
- it "should create a transform entry (with entry_type == :test) for every test entry" do
- run_task
- entries = @manifest.entries(:hidden => true)
-
- # find all entries referencing original source...
- source_entries = entries.reject do |entry|
- !(entry.original? && entry.filename =~ /^tests\//)
- end
- source_entries.size.should > 0 # precondition
-
- # final all test transform entries.
- test_entries = entries.reject { |e| e.entry_type != :test }
- test_entries.size.should eql(source_entries.size) # 1 for each entry?
- test_entries.each do |entry|
- source_entries.should include(entry.source_entry)
- source_entries.delete(entry.source_entry) # avoid double counting
- end
-
- # none should be left...
- source_entries.size.should == 0
- end
-
- # check the format of each entry...
- describe "transform entry" do
-
- before do
- run_task
- @entries = @manifest.entries.reject { |e| e.entry_type != :test }
- end
-
- it "changes the filename + build_path + url ext to .html" do
- @entries.each do |entry|
- File.extname(entry.filename).should == '.html'
- File.extname(entry.build_path).should == '.html'
- File.extname(entry.url).should == '.html'
- end
- end
-
- it "assigns a build_task of build:test:EXTNAME (from source_entry)" do
- @entries.each do |entry|
- extname = File.extname(entry.source_entry.filename)[1..-1]
- entry.build_task.to_s.should == "build:test:#{extname.downcase}"
- end
- end
-
- end
-
- it "should create a composite entry to generate a -index.json with test entries as source" do
- run_task
- entry = @manifest.entry_for('tests/-index.json')
-
- entry.should_not be_nil
- entry.entry_type.should == :resource
- entry.build_task.to_s.should == 'build:test:index.json'
-
- expected = @manifest.entries.reject { |e| e.entry_type != :test }
- entry.source_entries.size.should eql(expected.size)
- entry.source_entries.each do |entry|
- expected.should include(entry)
- expected.delete(entry) # avoid double counting
- end
- expected.size.should == 0 # should have an empty size...
- end
-
- it "should not hide -index.json source_entries (since they are test that need to be built)" do
- run_task
- entry = @manifest.entry_for('tests/-index.json')
- entry.source_entries.each do |entry|
- entry.should_not be_hidden
- end
- end
-
- it "should not generate an -index.json entry if tests not loaded" do
- run_task(false)
- entry = @manifest.entry_for('tests/-index.json')
- entry.should be_nil
- end
-
- end
-
- describe "manifest:prepare_build_tasks:sass" do
-
- def run_task
- @manifest.prepare!
- super('manifest:prepare_build_tasks:sass')
- end
-
- it "should run manifest:prepare_build_tasks:setup as prereq" do
- should_run('manifest:prepare_build_tasks:setup') { run_task }
- end
-
- it "should create a transform entry (with entry_type == :css) for every sass entry" do
- run_task
- entries = @manifest.entries(:hidden => true)
-
- # find all entries referencing original source...
- source_entries = entries.reject do |entry|
- !(entry.original? && entry.filename =~ /\.sass$/)
- end
- source_entries.size.should > 0 # precondition
-
- # final all test transform entries.
- test_entries = entries.reject { |e| e.entry_type != :css }
- test_entries.size.should eql(source_entries.size) # 1 for each entry?
- test_entries.each do |entry|
- source_entries.should include(entry.source_entry)
- source_entries.delete(entry.source_entry) # avoid double counting
- end
-
- # none should be left...
- source_entries.size.should == 0
- end
-
- # check the format of each entry...
- describe "sass -> css transform entry" do
-
- before do
- run_task
- @entries = @manifest.entries.reject do |e|
- !(e.entry_type == :css && e.source_entry.filename =~ /\.sass$/)
- end
- end
-
- it "changes the filename + build_path + url ext to .css" do
- @entries.each do |entry|
- File.extname(entry.filename).should == '.css'
- File.extname(entry.build_path).should == '.css'
- File.extname(entry.url).should == '.css'
- end
- end
-
- it "assigns a build_task of build:sass" do
- @entries.each do |entry|
- entry.build_task.to_s.should == 'build:sass'
- end
- end
-
- it "hides the source entry" do
- @entries.each do |entry|
- entry.source_entry.should be_hidden
- end
- end
-
- end # describe sass -> css transform entry
-
- end # describe manifest:prepare_build_tasks:sass
-
- describe "manifest:prepare_build_tasks:css" do
-
- def run_task
- @manifest.prepare!
- super('manifest:prepare_build_tasks:css')
- end
-
- it "should run manifest:prepare_build_tasks:setup && sass as prereq" do
- should_run('manifest:prepare_build_tasks:setup') { run_task }
- should_run('manifest:prepare_build_tasks:sass') { run_task }
- end
-
- describe "supports require() and sc_require() statements" do
-
- it "adds a entry.requires property to entrys with empty array of no requires are specified in file" do
- run_task
- entry = entry_for('no_require.css')
- entry.requires.should == []
- end
-
- it "searches files for require() & sc_requires() statements and adds them to entry.requires array -- (also should ignore any ext)" do
- run_task
- entry = entry_for('has_require.css')
- entry.requires.sort.should == ['demo2', 'no_require']
- end
-
- end
-
- describe "supports sc_resource() statement" do
- it "sets entry.resource = 'stylesheet' if no sc_resource statement is found in files" do
- run_task
- entry = entry_for('no_require.css')
- entry.resource.should == 'stylesheet'
- end
-
- it "searches files for sc_resource() statement and stores last value in entry.resource property" do
- run_task
- entry =entry_for 'sc_resource.css'
- entry.resource.should == 'bar'
- end
- end
-
- describe "combines stylesheet entries" do
-
- before do
- run_task
- end
-
- it "creates a combined stylesheet entry for each resource named in files" do
- # spot check...
- entry = entry_for 'stylesheet.css'
- entry.source_entries.should include(entry_for('has_require.css'))
- entry.source_entries.should include(entry_for('no_require.css'))
-
- entry = entry_for 'bar.css'
- entry.source_entries.should include(entry_for('sc_resource.css'))
- end
-
- it "entries have a build_task = build:css" do
- entry_for('stylesheet.css').build_task.should == 'build:css'
- entry_for('bar.css').build_task.should == 'build:css'
- end
-
- it "hides source entries" do
- %w(stylesheet.css bar.css).each do |filename|
- entry_for(filename).source_entries.each do |entry|
- entry.should be_hidden
- end
- end
- end
-
- end
-
- end # describe manifest:prepare_build_tasks:css
-
- describe "manifest:prepare_build_tasks:javascript" do
-
- def run_task
- @manifest.prepare!
- super('manifest:prepare_build_tasks:javascript')
- end
-
- it "should run manifest:prepare_build_tasks:setup as prereq" do
- should_run('manifest:prepare_build_tasks:setup') { run_task }
- end
-
- describe "supports require() and sc_require() statements" do
-
- it "adds a entry.requires property to entrys with empty array of no requires are specified in file" do
- run_task
- entry = entry_for('no_require.js')
- entry.requires.should == []
- end
-
- it "searches files for require() & sc_requires() statements and adds them to entry.requires array -- (also should ignore any ext)" do
- run_task
- entry = entry_for('has_require.js')
- entry.requires.sort.should == ['demo2', 'no_require']
- end
-
- end
-
- describe "supports sc_resource() statement" do
- it "sets entry.resource = 'stylesheet' if no sc_resource statement is found in files" do
- run_task
- entry = entry_for('no_require.js')
- entry.resource.should == 'javascript'
- end
-
- it "searches files for sc_resource() statement and stores last value in entry.resource property" do
- run_task
- entry =entry_for 'sc_resource.js'
- entry.resource.should == 'bar'
- end
- end
-
- describe "combines javascript entries" do
-
- before do
- run_task
- end
-
- it "creates a combined javascript entry for each resource named in files" do
- # spot check...
- entry = entry_for 'javascript.js'
- entry.source_entries.should include(entry_for('has_require.js'))
- entry.source_entries.should include(entry_for('no_require.js'))
-
- entry = entry_for 'bar.js'
- entry.source_entries.should include(entry_for('sc_resource.js'))
- end
-
- it "entries have a build_task = build:javascript" do
- entry_for('javascript.js').build_task.should == 'build:javascript'
- entry_for('bar.js').build_task.should == 'build:javascript'
- end
-
- it "hides source entries" do
- %w(javascript.js bar.js).each do |filename|
- entry_for(filename).source_entries.each do |entry|
- entry.should be_hidden
- end
- end
- end
-
- end
-
- end # describe manifest:prepare_build_tasks:css
-
- describe "manifest:prepare_build_tasks:html" do
-
- def run_task
- @manifest.prepare!
- super('manifest:prepare_build_tasks:html')
- end
-
- it "should run manifest:prepare_build_tasks:setup as prereq" do
- should_run('manifest:prepare_build_tasks:setup') { run_task }
- end
-
- describe "supports sc_resource() statement" do
- it "sets entry.resource = 'index' if no sc_resource statement is found in files" do
- run_task
- entry = entry_for('no_sc_resource.rhtml')
- entry.resource.should == 'index'
- end
-
- it "searches files for sc_resource() statement and stores last value in entry.resource property" do
- run_task
- entry = entry_for 'sc_resource.rhtml'
- entry.resource.should == 'bar'
- end
- end
-
- describe "annotates entries with render_task" do
-
- before do
- run_task
- end
-
- it "file.erb => render:erubis" do
- expected = entry_for('file_extension_test.html.erb')
- expected.render_task.should == "render:erubis"
- end
-
- it "file.haml => render:haml" do
- expected = entry_for('file_extension_test.haml')
- expected.render_task.should == "render:haml"
- end
-
- it "file.rhtml => render:erubis" do
- expected = entry_for('file_extension_test.rhtml')
- expected.render_task.should == "render:erubis"
- end
-
- end
-
- describe "combines html entries into one output file per resource" do
-
- before do
- run_task
- @index_entry = @manifest.entry_for 'index.html'
- @bar_entry = @manifest.entry_for('bar.html')
- end
-
- it "should be composite entries" do
- @index_entry.should be_composite
- @bar_entry.should be_composite
- end
-
- it "should include any files ending in .rhtml" do
- expected = entry_for('file_extension_test.rhtml')
- @index_entry.source_entries.should include(expected)
- end
-
- it "should include any files ending in .erb" do
- expected = entry_for('file_extension_test.html.erb')
- @index_entry.source_entries.should include(expected)
- end
-
- it "should include any files ending in .haml" do
- expected = entry_for('file_extension_test.haml')
- @index_entry.source_entries.should include(expected)
- end
-
- it "creates a combined index entry for each resource named in files" do
- # spot check...
- @index_entry.source_entries.should include(entry_for('no_sc_resource.rhtml'))
-
- @bar_entry.source_entries.should include(entry_for('sc_resource.rhtml'))
- end
-
- it "entries have a build_task = build:html" do
- @index_entry.build_task.should == 'build:html'
- @bar_entry.build_task.should == 'build:html'
- end
-
- it "hides source entries" do
- [@index_entry, @bar_entry].each do |entry|
- entry.source_entries.each do |source_entry|
- source_entry.should be_hidden
- end
- end
- end
-
- end
-
- end
-
-end
View
5 spec/lib/models/manifest/add_transform_spec.rb
@@ -58,6 +58,11 @@
@entry.should be_hidden
end
+ it "should mark the new entry as a transform" do
+ new_entry = @manifest.add_transform @entry, :build_task => 'foo'
+ new_entry.should be_transform
+ end
+
it "swaps extensions in filename, url, build_path, and staging_path if :ext option is provided" do
# Check preconditions
File.extname(@entry.filename).should == '.js'

0 comments on commit 332c3ab

Please sign in to comment.