<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -1,5 +1,30 @@
 module Headerize
   module JavascriptHelper
+    def add_javascript(*args)
+      @javascripts ||= []
+      @javascripts &lt;&lt; args
+
+      nil
+    end
+
+    def javascript_includes(opts = {})
+      return '' if @javascripts.nil?
+
+      indent_amt = opts[:indent] || 4
+
+      includes = @javascripts.inject('') do |str, files_and_opts|
+        str &lt;&lt; javascript_include_tag(*files_and_opts)
+      end
+
+      indent(includes, indent_amt)
+    end
+
+    private
+      # Indents the given string by the given amount. Does not indent the first
+      # line.
+      def indent(string, amt)
+        string.gsub /\n *([^\n]+)/m, &quot;\n#{' ' * amt}\\1&quot;
+      end
   end
 end
 </diff>
      <filename>lib/headerize/javascript_helper.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,8 +1,141 @@
 require File.dirname(__FILE__) + '/../spec_helper'
+require File.dirname(__FILE__) + '/../../lib/headerize/javascript_helper.rb'
 
-require 'headerize/javascript_helper'
 include Headerize
 
-describe JavascriptHelper do
+describe JavascriptHelper, 'when including a single file' do
+  it 'should return nothing' do
+    add_javascript('test').should be_nil
+  end
+end
+
+describe JavascriptHelper, 'when including multiple files' do
+  it 'should return nothing' do
+    add_javascript('test', 'second_test', 'magic').should be_nil
+  end
+end
+
+describe JavascriptHelper, 'when passing extra arguments to add_javascript' do
+  it 'should return nothing' do
+    add_javascript('test', 'magic', :cache =&gt; true).should be_nil
+  end
+end
+
+describe JavascriptHelper, 'when outputting scripts without files' do
+  it 'should return an empty string' do
+    javascript_includes.should be_empty
+  end
+end
+
+describe JavascriptHelper, 'when outputting with indentation but no scripts' do
+  it 'should return an empty string' do
+    javascript_includes(:indent =&gt; 8).should be_empty
+  end
+end
+
+describe JavascriptHelper, 'when outputting scripts with a single file' do
+  before(:each) do
+    add_javascript 'test'
+  end
+
+  it 'should use javascript_include_tag to include it' do
+    self.should_receive(:javascript_include_tag).with('test').and_return('test')
+
+    javascript_includes.should == 'test'
+  end
+end
+
+describe JavascriptHelper,
+    'when outputting scripts with multiple add_javascript arguments' do
+  before(:each) do
+    add_javascript 'test', 'magic', :cache =&gt; true
+  end
+
+  it 'should splat the arguments to javascript_include_tag' do
+    self.should_receive(:javascript_include_tag) \
+        .with('test', 'magic', :cache =&gt; true).and_return('test')
+
+    javascript_includes.should == 'test'
+  end
+end
+
+describe JavascriptHelper,
+    'when outputting scripts through multiple invocations' do
+  before(:each) do
+    add_javascript 'test'
+    add_javascript 'test2', 'magic'
+    add_javascript 'power'
+  end
+
+  it 'should call javascript_include_tag for each set ' +
+     'and concatenate the results' do
+    self.should_receive(:javascript_include_tag) \
+        .with('test').and_return('test')
+    self.should_receive(:javascript_include_tag) \
+        .with('test2', 'magic').and_return('test2')
+    self.should_receive(:javascript_include_tag) \
+        .with('power').and_return('test3')
+
+    includes = javascript_includes
+    includes.should =~ /^test/
+    includes.should =~ /test2/
+    includes.should =~ /test3$/
+  end
+end
+
+describe JavascriptHelper,
+    'when outputting scripts through multiple invocations with extra arguments' do
+  before(:each) do
+    add_javascript 'test', :cache =&gt; false
+    add_javascript 'test2', 'magic', :cache =&gt; 'power'
+    add_javascript 'power', :cache =&gt; true
+  end
+
+   it 'should splat the arguments to javascript_include_tag each time ' +
+      'and concatenate the results' do
+    self.should_receive(:javascript_include_tag) \
+        .with('test', :cache =&gt; false).and_return('test')
+    self.should_receive(:javascript_include_tag) \
+        .with('test2', 'magic', :cache =&gt; 'power').and_return('test2')
+    self.should_receive(:javascript_include_tag) \
+        .with('power', :cache =&gt; true).and_return('test3')
+
+    includes = javascript_includes
+    includes.should =~ /^test/
+    includes.should =~ /test2/
+    includes.should =~ /test3$/
+   end
+end
+
+describe JavascriptHelper, 'when outputting with indentation and one item' do
+  before(:each) do
+    self.stub!(:javascript_include_tag).and_return(&quot;test\n&quot;)
+
+    add_javascript 'test'
+  end
+
+  it 'should not indent the first line' do
+    javascript_includes(:indent =&gt; 8).should == &quot;test\n&quot;
+  end
+
+  it 'should not indent newlines with no text after them' do
+    javascript_includes(:indent =&gt; 8).should == &quot;test\n&quot;
+  end
+end
+
+describe JavascriptHelper, 'when outputting with indentation and one item' do
+  before(:each) do
+    self.stub!(:javascript_include_tag).and_return(&quot;test\npower\n&quot;)
+
+    add_javascript 'test', 'power'
+  end
+
+  it 'should not indent the first line' do
+    javascript_includes(:indent =&gt; 8).should =~ /^test$/
+  end
+
+  it 'should indent newlines with text after them' do
+    javascript_includes(:indent =&gt; 8).should =~ /^ {8}power$/
+  end
 end
 </diff>
      <filename>spec/headerize/javascript_helper_spec.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,6 +1,6 @@
 require File.dirname(__FILE__) + '/../spec_helper'
+require File.dirname(__FILE__) + '/../../lib/headerize/stylesheet_helper.rb'
 
-require 'headerize/stylesheet_helper'
 include Headerize
 
 describe StylesheetHelper do</diff>
      <filename>spec/headerize/stylesheet_helper_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>12e81630c4622065aeb9a87e3435c79868d2cb56</id>
    </parent>
  </parents>
  <author>
    <name>shadowfiend</name>
    <email>shadowfiend@ubuntu.Belkin</email>
  </author>
  <url>http://github.com/Shadowfiend/headerize/commit/3b6677869333e3bcc257f00602af7b2981b067bc</url>
  <id>3b6677869333e3bcc257f00602af7b2981b067bc</id>
  <committed-date>2008-06-07T10:34:17-07:00</committed-date>
  <authored-date>2008-06-07T10:34:17-07:00</authored-date>
  <message>Added JavascriptHelper specs and code.</message>
  <tree>e40a1417ad06df765704f4062e341c42e17d0668</tree>
  <committer>
    <name>shadowfiend</name>
    <email>shadowfiend@ubuntu.Belkin</email>
  </committer>
</commit>
