borrower 0.5.0 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,7 +3,7 @@ module Borrower
3
3
 
4
4
  def initialize content, options={}
5
5
  @content = content
6
- @comment_symbol = options.fetch(:comment) { default_comment_symbol }
6
+ @comment_symbol = pick_comment_symbol options
7
7
  end
8
8
 
9
9
  def output
@@ -12,8 +12,10 @@ module Borrower
12
12
 
13
13
  private
14
14
 
15
- def default_comment_symbol
16
- "#"
15
+ def pick_comment_symbol options
16
+ options.fetch(:comment) do
17
+ CommentSymbol.find_symbol_for options.fetch(:type) { "default" }
18
+ end
17
19
  end
18
20
 
19
21
  def merge_borrow_statements
@@ -26,5 +28,30 @@ module Borrower
26
28
  Content.get(path)
27
29
  end
28
30
 
31
+ module CommentSymbol
32
+ class << self
33
+
34
+ def find_symbol_for type
35
+ symbols.fetch(type) { default }
36
+ end
37
+
38
+ private
39
+
40
+ def default
41
+ "#"
42
+ end
43
+
44
+ def symbols
45
+ {
46
+ 'js' => '//',
47
+ 'javascript' => '//',
48
+ 'css' => '//',
49
+ 'stylesheet' => '//'
50
+ }
51
+ end
52
+
53
+ end
54
+ end
55
+
29
56
  end
30
57
  end
@@ -1,3 +1,3 @@
1
1
  module Borrower
2
- VERSION = "0.5.0"
2
+ VERSION = "0.6.0"
3
3
  end
data/lib/borrower.rb CHANGED
@@ -36,7 +36,7 @@ module Borrower::DSL
36
36
  def borrow path, options={}, &block
37
37
  destination = options.delete(:to) { raise ArgumentError, "missing 'to:' argument" }
38
38
  content = Borrower.take(path)
39
- content = Borrower.merge(content) if options.fetch(:merge) { false }
39
+ content = Borrower.merge(content, options) if options.fetch(:merge) { false }
40
40
  if block_given?
41
41
  content = yield content
42
42
  end
@@ -21,6 +21,11 @@ describe "moving files with a merge" do
21
21
  Borrower.merge("//= borrow 'foo.txt'", comment: "//" ).should == "hello I'm merged text"
22
22
  end
23
23
 
24
+ it "lets you pass file types to change the comment symbol" do
25
+ Borrower.merge( "//= borrow 'foo.txt'", type: 'js' ).should == "hello I'm merged text"
26
+ Borrower.merge( "//= borrow 'foo.txt'", type: 'css' ).should == "hello I'm merged text"
27
+ end
28
+
24
29
  it "handles multiple files to merge with" do
25
30
  given_file "woo.txt", "woo"
26
31
  given_file "multiple.txt", <<-content
@@ -5,6 +5,7 @@ describe Borrower do
5
5
  before :each do
6
6
  given_file "file.txt", "Hi I'm a file"
7
7
  given_file "merge.txt", "#= borrow '#{File.join( TMP, 'file.txt')}'"
8
+ given_file "merge.js", "//= borrow '#{File.join( TMP, 'file.txt')}'"
8
9
  end
9
10
 
10
11
  after :each do
@@ -13,6 +14,7 @@ describe Borrower do
13
14
 
14
15
  let (:local_file) { File.join( TMP, 'file.txt' ) }
15
16
  let (:merge_file) { File.join( TMP, 'merge.txt' ) }
17
+ let (:js_merge_file) { File.join( TMP, 'merge.js' ) }
16
18
  let (:remote_file) { "https://gist.github.com/stevenosloan/5578606/raw/97ab1305184bdeac33472f9f1fcc1c9e278a1bb3/dummy.txt" }
17
19
  let (:file_destination) { File.join( TMP, 'destination/file.txt' ) }
18
20
 
@@ -48,6 +50,11 @@ describe Borrower do
48
50
  Borrower.take( file_destination ).should == "Hi I'm a file"
49
51
  end
50
52
 
53
+ it "merges files with the file type it is passed" do
54
+ borrow js_merge_file, to: file_destination, merge: true, type: 'js'
55
+ Borrower.take( file_destination ).should == "Hi I'm a file"
56
+ end
57
+
51
58
  it "raises an error if missing arg with key 'to'" do
52
59
  expect{ borrow( "foo", away: "bar" )}.to raise_error(ArgumentError)
53
60
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: borrower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.5.0
4
+ version: 0.6.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: