shift 0.1.0 → 0.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (48) hide show
  1. data/CHANGELOG +20 -0
  2. data/README.md +105 -37
  3. data/Rakefile +1 -1
  4. data/TODO +3 -0
  5. data/bin/shifter +5 -0
  6. data/lib/shift.rb +42 -36
  7. data/lib/shift/action_map.rb +106 -0
  8. data/lib/shift/cli.rb +43 -0
  9. data/lib/shift/errors.rb +7 -3
  10. data/lib/shift/i/closure_compiler.rb +23 -0
  11. data/lib/shift/{c → i}/coffee_script.rb +6 -3
  12. data/lib/shift/i/echo.rb +9 -0
  13. data/lib/shift/{c → i}/rdiscount.rb +6 -2
  14. data/lib/shift/{c → i}/redcarpet.rb +6 -2
  15. data/lib/shift/{c → i}/sass.rb +6 -2
  16. data/lib/shift/{c → i}/uglify_js.rb +7 -3
  17. data/lib/shift/{c → i}/yui_compressor.rb +7 -3
  18. data/lib/shift/i/zlib_reader.rb +23 -0
  19. data/lib/shift/i/zlib_writer.rb +27 -0
  20. data/lib/shift/{c/identity.rb → interface.rb} +39 -42
  21. data/lib/shift/interface_list.rb +67 -0
  22. data/lib/shift/interfaces.rb +20 -0
  23. data/lib/shift/mapper.rb +95 -0
  24. data/lib/shift/mappings.rb +51 -28
  25. data/lib/shift/mappings.yml +6 -0
  26. data/lib/shift/string.rb +125 -0
  27. data/shift.gemspec +3 -2
  28. data/test/data/letter.echo +0 -5
  29. data/test/helper.rb +2 -12
  30. data/test/{c → i}/closure_compiler_test.rb +6 -2
  31. data/test/{c → i}/coffee_script_test.rb +6 -2
  32. data/test/i/rdiscount_test.rb +22 -0
  33. data/test/i/redcarpet_test.rb +22 -0
  34. data/test/i/sass_test.rb +19 -0
  35. data/test/{c → i}/uglify_js_test.rb +6 -2
  36. data/test/{c → i}/yui_compressor_test.rb +6 -2
  37. data/test/i/zlib_reader.rb +24 -0
  38. data/test/interface_test.rb +60 -0
  39. data/test/mapper_test.rb +144 -0
  40. data/test/shift_test.rb +12 -43
  41. data/test/string_test.rb +39 -0
  42. metadata +39 -24
  43. data/lib/shift/c/closure_compiler.rb +0 -19
  44. data/test/c/identity_test.rb +0 -79
  45. data/test/c/rdiscount_test.rb +0 -18
  46. data/test/c/redcarpet_test.rb +0 -18
  47. data/test/c/sass_test.rb +0 -14
  48. data/test/support.rb +0 -37
@@ -0,0 +1,22 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'interface_test')
2
+
3
+
4
+ class RedCarpetTest < InterfaceTest
5
+
6
+ def subject
7
+ Shift::Redcarpet
8
+ end
9
+
10
+ def instance
11
+ subject.new
12
+ end
13
+
14
+ def transformations
15
+ { 'hello' => "<p>hello</p>\n" }
16
+ end
17
+
18
+ def name_transformations
19
+ { 'doc.md' => 'doc.html' }
20
+ end
21
+
22
+ end
@@ -0,0 +1,19 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'interface_test')
2
+
3
+
4
+ class SassTest < InterfaceTest
5
+
6
+ def subject
7
+ Shift::Sass
8
+ end
9
+
10
+ def transformations
11
+ {"#footer\n :height 200px" => "#footer {\n height: 200px; }\n"}
12
+ end
13
+
14
+ def name_transformations
15
+ { 'sheet.sass' => 'sheet.css' }
16
+ end
17
+
18
+
19
+ end
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(__FILE__), 'identity_test')
1
+ require File.join(File.dirname(__FILE__), '..', 'interface_test')
2
2
 
3
3
 
4
- class UglifyJSTest < IdentityTest
4
+ class UglifyJSTest < InterfaceTest
5
5
 
6
6
  FUNCTION = <<-eos
7
7
  function hello(name) {
@@ -30,4 +30,8 @@ class UglifyJSTest < IdentityTest
30
30
  }
31
31
  end
32
32
 
33
+ def name_transformations
34
+ { 'script.js' => 'script.min.js' }
35
+ end
36
+
33
37
  end
@@ -1,7 +1,7 @@
1
- require File.join(File.dirname(__FILE__), 'identity_test')
1
+ require File.join(File.dirname(__FILE__), '..', 'interface_test')
2
2
 
3
3
 
4
- class YUICompressorTest < IdentityTest
4
+ class YUICompressorTest < InterfaceTest
5
5
 
6
6
  FUNCTION = <<-eos
7
7
  function hello(name) {
@@ -30,4 +30,8 @@ class YUICompressorTest < IdentityTest
30
30
  }
31
31
  end
32
32
 
33
+ def name_transformations
34
+ { 'script.js' => 'script.min.js' }
35
+ end
36
+
33
37
  end
@@ -0,0 +1,24 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'interface_test')
2
+
3
+
4
+ class ZlibReaderTest < InterfaceTest
5
+
6
+ def subject
7
+ Shift::ZlibReader
8
+ end
9
+
10
+ def transformations
11
+ {"\x1F\x8B\b\x00w\xC5\xCEM\x00\x03\xCBH\xCD\xC9\xC9\a\x00\x86\xA6\x106\x05\x00\x00\x00" => "hello"}
12
+ end
13
+
14
+ def name_transformations
15
+ {
16
+ 'file.js.gz' => 'file',
17
+ 'file.gz' => 'file',
18
+ 'file' => 'file',
19
+ '' => '',
20
+ nil => nil
21
+ }
22
+ end
23
+
24
+ end
@@ -0,0 +1,60 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+
4
+ module Unavabelizer
5
+ def available?; false; end
6
+ end
7
+
8
+ class InterfaceTest < TestCase
9
+
10
+ def subject
11
+ Shift::Echo
12
+ end
13
+
14
+ def instance
15
+ @instance ||= subject.new(options)
16
+ end
17
+
18
+ def options
19
+ {}
20
+ end
21
+
22
+ def transformations
23
+ { 'echo' => 'echo', '' => '' }
24
+ end
25
+
26
+ def name_transformations
27
+ { '' => '', 'identity.id' => 'identity.id' }
28
+ end
29
+
30
+ test 'instructions' do
31
+ unless subject == Shift::Interface
32
+ refute_same subject.instructions,
33
+ subject.superclass.instructions,
34
+ 'gives instructions'
35
+ end
36
+ end
37
+
38
+ test 'has_default_instance' do
39
+ assert_instance_of subject, subject.default
40
+ end
41
+
42
+ test 'process' do
43
+ transformations.each do |a, b|
44
+ assert_equal b, instance.process(a)
45
+ end
46
+ end
47
+
48
+ test 'rename' do
49
+ name_transformations.each do |a, b|
50
+ assert_equal b, instance.rename(a)
51
+ end
52
+ end
53
+
54
+
55
+ test 'initialize when unavailable' do
56
+ wrap = Class.new(subject).extend(Unavabelizer)
57
+ assert_raises(Shift::DependencyError) { wrap.new }
58
+ end
59
+
60
+ end
@@ -0,0 +1,144 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+ class UnavailableInterface < Shift::Interface
4
+ def self.instructions; 'meditate'; end
5
+ def self.available?; false; end
6
+ end
7
+
8
+ class NullInterface < Shift::Interface
9
+ def self.available?; true; end
10
+ def process(str); ''; end
11
+ end
12
+
13
+
14
+ class MapperTest < TestCase
15
+
16
+ def map(*args)
17
+ backup = Shift::MAP.dup
18
+ Shift.map(*args)
19
+ yield
20
+ Shift::MAP.clear.merge!(backup)
21
+ end
22
+
23
+ def map_global(*args)
24
+ backup = Shift.global.dup
25
+ Shift.global.map(*args)
26
+ yield
27
+ Shift.global = backup
28
+ end
29
+
30
+ # ---
31
+
32
+ test 'type lookup' do
33
+ assert_equal Shift[:echo], Shift::Echo
34
+ end
35
+
36
+ test 'path long type lookup' do
37
+ map('null.void', NullInterface) do
38
+ assert_equal Shift['/a/b/c/treaty.null.void'], NullInterface
39
+ end
40
+ end
41
+
42
+ test 'action lookup' do
43
+ map('toupe',
44
+ :default => %w{NullInterface},
45
+ :custom => %w{Interface}
46
+ ) do
47
+ assert_equal Shift['toupe'], NullInterface
48
+ assert_equal Shift['toupe', :custom], Shift::Interface
49
+ end
50
+ end
51
+
52
+ test 'unknown format' do
53
+ assert_raises(Shift::UnknownFormatError) do
54
+ Shift['thereis.noformatforthis']
55
+ end
56
+ end
57
+
58
+ test 'known format and unknown action' do
59
+ assert_raises(Shift::UnknownActionError) do
60
+ Shift[:echo, :boil]
61
+ end
62
+ end
63
+
64
+ test 'unknown format and known global action' do
65
+ map_global(:nullify => NullInterface) do
66
+ assert_equal Shift[:rhubarb, :nullify], NullInterface
67
+ assert_equal Shift[nil, :nullify], NullInterface
68
+ end
69
+ end
70
+
71
+ test 'known format and known global action' do
72
+ map_global(:nullify => NullInterface) do
73
+ assert_equal Shift[:echo, :nullify], NullInterface
74
+ end
75
+ end
76
+
77
+ test 'prioritizes' do
78
+ map(:prioritized,
79
+ %w{UnavailableInterface NullInterface Interface}
80
+ ) do
81
+ assert_equal Shift[:prioritized], NullInterface
82
+ end
83
+ end
84
+
85
+ test 'when unavailable' do
86
+ map(:unavailable, %w{UnavailableInterface}*10) do
87
+ begin
88
+ Shift[:unavailable]
89
+ assert false, 'raises error'
90
+ rescue Shift::DependencyError => err
91
+ assert_match /meditate/, err.message, 'gives help'
92
+ end
93
+ end
94
+ end
95
+
96
+ # ---
97
+
98
+ test 'links' do
99
+ map(:linked,
100
+ :default => :dog,
101
+ :dog => :cat,
102
+ :cat => :mouse,
103
+ :mouse => NullInterface
104
+ ) do
105
+ assert_equal Shift[:linked], NullInterface
106
+ end
107
+ end
108
+
109
+ test 'invalid link' do
110
+ assert_raises Shift::MappingError do
111
+ map(:badlink, :bad_link => :space) { nil }
112
+ end
113
+ end
114
+
115
+ test 'cyclic link' do
116
+ assert_raises Shift::MappingError do
117
+ map(:cycle,
118
+ :back => :onwards,
119
+ :onwards => :fourth,
120
+ :fourth => :back
121
+ ) { nil }
122
+ end
123
+ end
124
+
125
+ test 'allows mapping class' do
126
+ map(:kluss, NullInterface) do
127
+ assert_equal Shift[:kluss], NullInterface
128
+ end
129
+ end
130
+
131
+ test 'synonym' do
132
+ map(:blubber, :blbr, :br, %w{Interface}) do
133
+ assert_equal Shift[:blubber], Shift::Interface
134
+ assert_equal Shift[:blbr], Shift::Interface
135
+ assert_equal Shift[:br], Shift::Interface
136
+ end
137
+ end
138
+
139
+ test 'inspect' do
140
+ assert_instance_of(String, Shift.inspect_actions)
141
+ end
142
+
143
+ end
144
+
@@ -1,6 +1,4 @@
1
1
  require File.join(File.dirname(__FILE__), 'helper')
2
- require File.join(File.dirname(__FILE__), 'support')
3
-
4
2
 
5
3
 
6
4
 
@@ -9,56 +7,27 @@ class ShiftTest < TestCase
9
7
 
10
8
  test 'read nonexistant file' do
11
9
  assert_raises(Errno::ENOENT) do
12
- Shift.read('/ubongobaluba-hepp-piglets/seriously.echo')
10
+ Shift.read('/piglets/seriously.echo')
13
11
  end
14
12
  end
15
13
 
16
- test 'read file' do
17
- assert_match Shift.read(file 'letter.echo'),
18
- /electric power drill/
19
- end
20
-
21
- test 'reads existing file and writes result' do
22
- with_tempfile do |path|
23
- Shift.read(file('letter.echo')).write(path)
24
- assert_equal(IO.read(file 'letter.echo'), IO.read(path))
14
+ test 'read' do
15
+ with_tempfile('orangutan') do |path|
16
+ assert_equal Shift.read(path), 'orangutan'
25
17
  end
26
18
  end
27
19
 
28
-
29
- # mappings
30
-
31
- test 'has mappings' do
32
- assert_kind_of Hash, Shift::MAPPINGS
33
- end
34
-
35
- test 'reads unmapped file' do
36
- assert_raises(Shift::UnknownFormatError) do
37
- Shift.read('oy-oy-oy.noformatforthis')
20
+ test 'concat' do
21
+ with_tempfile('hello ') do |a|
22
+ with_tempfile('there') do |b|
23
+ assert_equal Shift.concat(a, b), 'hello there'
24
+ end
38
25
  end
39
26
  end
40
27
 
41
- test 'gets available mapping' do
42
- assert_equal Shift[:echo], Shift::Identity, 'given type'
43
- assert_equal Shift['treaty.null'], NullComponent, 'given path'
44
- assert_equal Shift['some/path/hey.bingo.bongo'],
45
- NullComponent, 'with detailed mapping'
46
- end
47
-
48
- test 'prioritizes' do
49
- assert_equal Shift['file.null'], NullComponent,
50
- 'first when available'
51
- assert_equal Shift['file.prioritized'], NullComponent,
52
- 'second when available but not first'
53
- end
54
-
55
- test 'raises DependencyError' do
56
- begin
57
- Shift[:unavailable] # defined in test/support.rb
58
- assert false, 'when no components available'
59
- rescue Shift::DependencyError => err
60
- assert_match /meditate/, err.message, 'with helpful message'
61
- end
28
+ test 'constructors' do
29
+ assert_instance_of Shift::String, Shift()
30
+ assert_instance_of Shift::String, Shift.new
62
31
  end
63
32
 
64
33
  end
@@ -0,0 +1,39 @@
1
+ require File.join(File.dirname(__FILE__), 'helper')
2
+
3
+
4
+ class StringTest < TestCase
5
+
6
+ test 'format' do
7
+ assert_nil Shift::String.new.format
8
+ assert_equal Shift::String.new('hey', :md).format, :md
9
+ end
10
+
11
+ test 'read_append' do
12
+ with_tempfile('cauliflower', '.md') do |path|
13
+ s = Shift::String.new
14
+ s.read_append(path)
15
+ assert_equal s, 'cauliflower'
16
+ end
17
+ end
18
+
19
+ test 'write' do
20
+ with_tempfile('', 'md') do |path|
21
+ Shift::String.new('hello', path).write
22
+ assert_equal IO.read(path), 'hello'
23
+ end
24
+ end
25
+
26
+
27
+ test 'process and type override' do
28
+ assert_equal Shift::String.new('hey', :pig).
29
+ process(:render, :md), "<p>hey</p>\n"
30
+ end
31
+
32
+ test 'dynamic method chaining' do
33
+ r = Shift::String.new('42', 'life.coffee').compile.minify
34
+ assert_match r, /42/
35
+ assert_equal r.name, 'life.min.js'
36
+ Shift::String.new('hello').gzip
37
+ end
38
+
39
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
- - 1
7
+ - 4
8
8
  - 0
9
- version: 0.1.0
9
+ version: 0.4.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Jostein Berre Eliassen
@@ -14,14 +14,14 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-09 00:00:00 +02:00
17
+ date: 2011-05-14 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
21
- description: Shift is a generic interface to different compilers, compressors, etc. What the Tilt gem does for template languages, Shift does for compilers and compressors.
21
+ description: Shift is a generic interface to different compilers, compressors, and so on. You can use it to build chains, like Shift.read("cup.coffee").compile.minify.write
22
22
  email: josteinpost@gmail.com
23
- executables: []
24
-
23
+ executables:
24
+ - shifter
25
25
  extensions: []
26
26
 
27
27
  extra_rdoc_files: []
@@ -29,34 +29,49 @@ extra_rdoc_files: []
29
29
  files:
30
30
  - .gitignore
31
31
  - .yardopts
32
+ - CHANGELOG
32
33
  - LICENSE
33
34
  - README.md
34
35
  - Rakefile
36
+ - TODO
37
+ - bin/shifter
35
38
  - lib/shift.rb
36
- - lib/shift/c/closure_compiler.rb
37
- - lib/shift/c/coffee_script.rb
38
- - lib/shift/c/identity.rb
39
- - lib/shift/c/rdiscount.rb
40
- - lib/shift/c/redcarpet.rb
41
- - lib/shift/c/sass.rb
42
- - lib/shift/c/uglify_js.rb
43
- - lib/shift/c/yui_compressor.rb
39
+ - lib/shift/action_map.rb
40
+ - lib/shift/cli.rb
44
41
  - lib/shift/errors.rb
42
+ - lib/shift/i/closure_compiler.rb
43
+ - lib/shift/i/coffee_script.rb
44
+ - lib/shift/i/echo.rb
45
+ - lib/shift/i/rdiscount.rb
46
+ - lib/shift/i/redcarpet.rb
47
+ - lib/shift/i/sass.rb
48
+ - lib/shift/i/uglify_js.rb
49
+ - lib/shift/i/yui_compressor.rb
50
+ - lib/shift/i/zlib_reader.rb
51
+ - lib/shift/i/zlib_writer.rb
52
+ - lib/shift/interface.rb
53
+ - lib/shift/interface_list.rb
54
+ - lib/shift/interfaces.rb
55
+ - lib/shift/mapper.rb
45
56
  - lib/shift/mappings.rb
57
+ - lib/shift/mappings.yml
58
+ - lib/shift/string.rb
46
59
  - shift.gemspec
47
- - test/c/closure_compiler_test.rb
48
- - test/c/coffee_script_test.rb
49
- - test/c/identity_test.rb
50
- - test/c/rdiscount_test.rb
51
- - test/c/redcarpet_test.rb
52
- - test/c/sass_test.rb
53
- - test/c/uglify_js_test.rb
54
- - test/c/yui_compressor_test.rb
55
60
  - test/data/letter.echo
56
61
  - test/data/piglet.coffee
57
62
  - test/helper.rb
63
+ - test/i/closure_compiler_test.rb
64
+ - test/i/coffee_script_test.rb
65
+ - test/i/rdiscount_test.rb
66
+ - test/i/redcarpet_test.rb
67
+ - test/i/sass_test.rb
68
+ - test/i/uglify_js_test.rb
69
+ - test/i/yui_compressor_test.rb
70
+ - test/i/zlib_reader.rb
71
+ - test/interface_test.rb
72
+ - test/mapper_test.rb
58
73
  - test/shift_test.rb
59
- - test/support.rb
74
+ - test/string_test.rb
60
75
  has_rdoc: true
61
76
  homepage: http://github.com/jbe/shift
62
77
  licenses:
@@ -88,6 +103,6 @@ rubyforge_project:
88
103
  rubygems_version: 1.3.7
89
104
  signing_key:
90
105
  specification_version: 3
91
- summary: Shift is a generic interface to different compilers, compressors, etc.
106
+ summary: Compiler and transformer interface framework
92
107
  test_files: []
93
108