fixer_upper 0.3.0 → 0.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: f17d076ad0560c75356d33ca5492fbb5adb288bc
4
- data.tar.gz: 239fc8b0a65b17a08134ed437a7286060b68bdf1
3
+ metadata.gz: cd048ff747c17e9b203c63f89ba9c39ac1d7894b
4
+ data.tar.gz: ad1cf61e1c489d37519618782692f3c42db748d6
5
5
  SHA512:
6
- metadata.gz: ee1c19957a62ebb59c34cca172fb9a5f2babc992309672e83a75b8396c17dc25932e389309a5cce5f26476cf99f1d8682479b6e2bc031581b87f76218d07f0f8
7
- data.tar.gz: 3c2ca497612378216dc759246b7c2052065061dd6cbf326b3caaae7703702c8d0826ba30490f95510d95ef78d0faaa0312156c36cfeedc9070aab936696d48b5
6
+ metadata.gz: fccbaf7810c6ef7f114f7021afa0b0e7f5075d1bcfbf3206411b37baa1b62272612320deec52dcdc14477b3b4dd2985044be915dffc2b47f2f9e8d83439d6d23
7
+ data.tar.gz: 92b70790d2bda9592d21a4bb7a8fdd256a3e741be62e13802140238b566dab186afb0cdf3ccc16aea84ce1ce48893f634d043a2bbbf787f0aa3c083085bed7e4
data/.gitignore CHANGED
@@ -7,3 +7,5 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+
11
+ /.sass-cache/
data/.rubocop.yml CHANGED
@@ -8,6 +8,10 @@ Metrics/LineLength:
8
8
  IgnoredPatterns:
9
9
  - !ruby/regexp /^\s*#/
10
10
 
11
+ Metrics/MethodLength:
12
+ Exclude:
13
+ - test/**/*.rb
14
+
11
15
  Style/AlignParameters:
12
16
  EnforcedStyle: with_fixed_indentation
13
17
 
data/.travis.yml CHANGED
@@ -2,4 +2,17 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.4.0
5
- before_install: gem install bundler -v 1.14.6
5
+ - 2.3
6
+ - 2.2
7
+ - 2.1
8
+ - ruby-head
9
+ cache: bundler
10
+ before_install:
11
+ - gem install bundler -v 1.15.0
12
+ notifications:
13
+ email: false
14
+ matrix:
15
+ fast_finish: true
16
+ allow_failures:
17
+ - rvm: ruby-head
18
+ - rvm: 2.1
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # FixerUpper
2
2
 
3
+ [![Build Status](https://travis-ci.org/zachahn/fixer_upper.svg?branch=master)](https://travis-ci.org/zachahn/fixer_upper)
4
+
3
5
  You have a file and it just has so much potential.
4
6
 
5
7
  Gut job or not, FixerUpper makes that file into the result of your dreams,
data/fixer_upper.gemspec CHANGED
@@ -21,9 +21,12 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
+ spec.required_ruby_version = ">= 2.1.0"
25
+
24
26
  spec.add_development_dependency "bundler", "~> 1.14"
25
27
  spec.add_development_dependency "rake", "~> 10.0"
26
28
  spec.add_development_dependency "minitest", "~> 5.0"
27
29
  spec.add_development_dependency "pry"
28
30
  spec.add_development_dependency "rubocop"
31
+ spec.add_development_dependency "sass"
29
32
  end
data/lib/fixer_upper.rb CHANGED
@@ -1,3 +1,4 @@
1
+ require "fixer_upper/contractor"
1
2
  require "fixer_upper/error"
2
3
  require "fixer_upper/renovation"
3
4
  require "fixer_upper/version"
@@ -20,29 +21,43 @@ class FixerUpper
20
21
  @engine_registry[key]
21
22
  end
22
23
 
23
- def renovate(filepath, contents = nil, **options)
24
+ def renovate(filepath, contents = nil, **options, &block)
24
25
  @renovation.renovate(
25
26
  filepath: filepath,
26
27
  text: contents,
27
28
  options: options,
29
+ block: block,
28
30
  bang: false
29
31
  )
30
32
  end
31
33
 
32
- def renovate!(filepath, contents = nil, **options)
34
+ def renovate!(filepath, contents = nil, **options, &block)
33
35
  @renovation.renovate(
34
36
  filepath: filepath,
35
37
  text: contents,
36
38
  options: options,
39
+ block: block,
37
40
  bang: true
38
41
  )
39
42
  end
40
43
 
41
- def diy(text, *engines, **options)
42
- @renovation.diy(text: text, engines: engines, options: options, bang: false)
44
+ def diy(text, *engines, **options, &block)
45
+ @renovation.diy(
46
+ text: text,
47
+ engines: engines,
48
+ options: options,
49
+ block: block,
50
+ bang: false
51
+ )
43
52
  end
44
53
 
45
- def diy!(text, *engines, **options)
46
- @renovation.diy(text: text, engines: engines, options: options, bang: true)
54
+ def diy!(text, *engines, **options, &block)
55
+ @renovation.diy(
56
+ text: text,
57
+ engines: engines,
58
+ options: options,
59
+ block: block,
60
+ bang: true
61
+ )
47
62
  end
48
63
  end
@@ -0,0 +1,77 @@
1
+ class FixerUpper
2
+ class Contractor
3
+ def initialize(registry, options)
4
+ @registry = registry
5
+ @options = options
6
+ end
7
+
8
+ def call(text:, engines:, options:, filepath:, block:, bang:)
9
+ engines.reduce(text) do |memo, engine_name|
10
+ engine = find_engine(engine_name, bang)
11
+
12
+ if engine.nil?
13
+ next memo
14
+ end
15
+
16
+ parameters = parameters_for(engine)
17
+ merged_options =
18
+ options_for_engine(engine_name, options, parameters, filepath)
19
+
20
+ engine_invoke(engine, memo, merged_options, parameters, block)
21
+ end
22
+ end
23
+
24
+ private
25
+
26
+ def find_engine(engine_name, bang)
27
+ if bang
28
+ engine_or_raise(engine_name)
29
+ else
30
+ engine_or_nil(engine_name)
31
+ end
32
+ end
33
+
34
+ def engine_invoke(engine, text, options, parameters, block)
35
+ if options.any? && parameters.count >= 2
36
+ engine.call(text, **options, &block)
37
+ else
38
+ engine.call(text, &block)
39
+ end
40
+ end
41
+
42
+ def parameters_for(engine)
43
+ if engine.respond_to?(:parameters)
44
+ engine.parameters
45
+ else
46
+ engine.method(:call).parameters
47
+ end
48
+ end
49
+
50
+ def options_for_engine(engine_name, local_options, parameters, filepath)
51
+ default_options = @options[engine_name] || {}
52
+ specific_options = local_options[engine_name.to_sym] || {}
53
+
54
+ merged_options = default_options.merge(specific_options)
55
+
56
+ if parameters.include?([:keyreq, :filepath])
57
+ merged_options[:filepath] = filepath
58
+ end
59
+
60
+ merged_options
61
+ end
62
+
63
+ def engine_or_nil(engine_name)
64
+ @registry[engine_name]
65
+ end
66
+
67
+ def engine_or_raise(engine_name)
68
+ found_engine = @registry[engine_name]
69
+
70
+ if found_engine
71
+ found_engine
72
+ else
73
+ raise Error::EngineNotFound, "unknown engine: `#{engine_name}`"
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,13 @@
1
+ class FixerUpper
2
+ module Engine
3
+ class Erb
4
+ def call(text, scope:, filepath:, &block)
5
+ scope_binding = scope.instance_eval { binding }
6
+
7
+ erb = ::ERB.new(text)
8
+ erb.filename = filepath
9
+ erb.result(scope_binding)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ class FixerUpper
2
+ module Engine
3
+ class Noop
4
+ def call(text)
5
+ text
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,12 @@
1
+ class FixerUpper
2
+ module Engine
3
+ class Scss
4
+ def call(text, filepath:, **options)
5
+ options = options.merge(syntax: :scss, filename: filepath)
6
+
7
+ engine = ::Sass::Engine.new(text, **options)
8
+ engine.render
9
+ end
10
+ end
11
+ end
12
+ end
@@ -5,62 +5,33 @@ class FixerUpper
5
5
  @options = options
6
6
  end
7
7
 
8
- def renovate(filepath:, text: nil, options:, bang:)
8
+ def renovate(filepath:, text: nil, options:, block: nil, bang:)
9
9
  contents = file_contents(filepath, text)
10
10
 
11
11
  diy(
12
12
  text: contents,
13
13
  engines: extensions(filepath).reverse,
14
14
  options: options,
15
+ filepath: filepath,
16
+ block: block,
15
17
  bang: bang
16
18
  )
17
19
  end
18
20
 
19
- def diy(text:, engines:, options:, bang:)
20
- engines.reduce(text) do |memo, engine_name|
21
- engine = find_engine(engine_name, bang)
22
-
23
- merged_options = options_for_engine(engine_name, options)
24
-
25
- if merged_options.any? && engine.method(:call).parameters.count >= 2
26
- engine.call(memo, **merged_options)
27
- else
28
- engine.call(memo)
29
- end
30
- end
21
+ def diy(text:, engines:, options:, filepath: nil, block: nil, bang:)
22
+ contractor = Contractor.new(@registry, @options)
23
+ contractor.call(
24
+ text: text,
25
+ engines: engines,
26
+ options: options,
27
+ filepath: filepath,
28
+ block: block,
29
+ bang: bang
30
+ )
31
31
  end
32
32
 
33
33
  private
34
34
 
35
- def options_for_engine(engine_name, local_options)
36
- default_options = @options[engine_name] || {}
37
- specific_options = local_options[engine_name.to_sym] || {}
38
-
39
- default_options.merge(specific_options)
40
- end
41
-
42
- def find_engine(engine_name, bang)
43
- if bang
44
- engine_or_raise(engine_name)
45
- else
46
- engine_or_nil(engine_name)
47
- end
48
- end
49
-
50
- def engine_or_nil(engine_name)
51
- @registry[engine_name]
52
- end
53
-
54
- def engine_or_raise(engine_name)
55
- found_engine = @registry[engine_name]
56
-
57
- if found_engine
58
- found_engine
59
- else
60
- raise Error::EngineNotFound, "unknown engine: `#{engine_name}`"
61
- end
62
- end
63
-
64
35
  def file_contents(filepath, contents)
65
36
  if contents
66
37
  contents
@@ -1,3 +1,3 @@
1
1
  class FixerUpper
2
- VERSION = "0.3.0".freeze
2
+ VERSION = "0.4.0".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fixer_upper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Zach Ahn
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-05-22 00:00:00.000000000 Z
11
+ date: 2017-05-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - ">="
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: sass
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  description: Simple interface for template engines
84
98
  email:
85
99
  - engineering@zachahn.com
@@ -100,6 +114,10 @@ files:
100
114
  - bin/setup
101
115
  - fixer_upper.gemspec
102
116
  - lib/fixer_upper.rb
117
+ - lib/fixer_upper/contractor.rb
118
+ - lib/fixer_upper/engine/erb.rb
119
+ - lib/fixer_upper/engine/noop.rb
120
+ - lib/fixer_upper/engine/scss.rb
103
121
  - lib/fixer_upper/error.rb
104
122
  - lib/fixer_upper/renovation.rb
105
123
  - lib/fixer_upper/version.rb
@@ -115,7 +133,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
115
133
  requirements:
116
134
  - - ">="
117
135
  - !ruby/object:Gem::Version
118
- version: '0'
136
+ version: 2.1.0
119
137
  required_rubygems_version: !ruby/object:Gem::Requirement
120
138
  requirements:
121
139
  - - ">="