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 +4 -4
- data/.gitignore +2 -0
- data/.rubocop.yml +4 -0
- data/.travis.yml +14 -1
- data/README.md +2 -0
- data/fixer_upper.gemspec +3 -0
- data/lib/fixer_upper.rb +21 -6
- data/lib/fixer_upper/contractor.rb +77 -0
- data/lib/fixer_upper/engine/erb.rb +13 -0
- data/lib/fixer_upper/engine/noop.rb +9 -0
- data/lib/fixer_upper/engine/scss.rb +12 -0
- data/lib/fixer_upper/renovation.rb +13 -42
- data/lib/fixer_upper/version.rb +1 -1
- metadata +21 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cd048ff747c17e9b203c63f89ba9c39ac1d7894b
|
4
|
+
data.tar.gz: ad1cf61e1c489d37519618782692f3c42db748d6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fccbaf7810c6ef7f114f7021afa0b0e7f5075d1bcfbf3206411b37baa1b62272612320deec52dcdc14477b3b4dd2985044be915dffc2b47f2f9e8d83439d6d23
|
7
|
+
data.tar.gz: 92b70790d2bda9592d21a4bb7a8fdd256a3e741be62e13802140238b566dab186afb0cdf3ccc16aea84ce1ce48893f634d043a2bbbf787f0aa3c083085bed7e4
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/.travis.yml
CHANGED
@@ -2,4 +2,17 @@ sudo: false
|
|
2
2
|
language: ruby
|
3
3
|
rvm:
|
4
4
|
- 2.4.0
|
5
|
-
|
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(
|
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(
|
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
|
@@ -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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
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
|
data/lib/fixer_upper/version.rb
CHANGED
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.
|
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-
|
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:
|
136
|
+
version: 2.1.0
|
119
137
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
120
138
|
requirements:
|
121
139
|
- - ">="
|