fixer_upper 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e1136862e570043432fd2d7de7ac2fbafaa62094
4
+ data.tar.gz: 18adf119e492348a4661ad4aaf2ed40c9f7e6931
5
+ SHA512:
6
+ metadata.gz: b9e5877c91693e1372bf6d30ce0a7bfea2fdf271f55231fda302e2aa7e80c2e7baff03b1738656649090f72e027c9748835b13d2136935d5fe0ab047f108f906
7
+ data.tar.gz: 469e480f850f30dde9a8efe018b335bb34a43cc1d4adfdf9add1859633caf8ff014cbeb477c49586d702ba73daa1162dd7a37780d9b7bb97c4df0238b521f4ca
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rubocop.yml ADDED
@@ -0,0 +1,54 @@
1
+ AllCops:
2
+ DisplayCopNames: true
3
+
4
+ Bundler/OrderedGems:
5
+ Enabled: false
6
+
7
+ Metrics/LineLength:
8
+ IgnoredPatterns:
9
+ - !ruby/regexp /^\s*#/
10
+
11
+ Style/AlignParameters:
12
+ EnforcedStyle: with_fixed_indentation
13
+
14
+ Style/AsciiComments:
15
+ Enabled: false
16
+
17
+ Style/Documentation:
18
+ Enabled: false
19
+
20
+ Style/EmptyMethod:
21
+ Enabled: false
22
+
23
+ Style/ExtraSpacing:
24
+ AllowForAlignment: false
25
+
26
+ Style/FrozenStringLiteralComment:
27
+ Enabled: false
28
+
29
+ Style/GuardClause:
30
+ Enabled: false
31
+
32
+ Style/IfUnlessModifier:
33
+ Enabled: false
34
+
35
+ Style/MultilineMethodCallIndentation:
36
+ EnforcedStyle: indented_relative_to_receiver
37
+
38
+ Style/NegatedIf:
39
+ Enabled: false
40
+
41
+ Style/SpaceInLambdaLiteral:
42
+ EnforcedStyle: require_space
43
+
44
+ Style/StringLiterals:
45
+ EnforcedStyle: double_quotes
46
+
47
+ Style/StringLiteralsInInterpolation:
48
+ Enabled: false
49
+
50
+ Style/TrailingCommaInArguments:
51
+ EnforcedStyleForMultiline: comma
52
+
53
+ Style/TrailingCommaInLiteral:
54
+ EnforcedStyleForMultiline: comma
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.6
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in fixer_upper.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2017 Zach Ahn
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,67 @@
1
+ # FixerUpper
2
+
3
+ You have a file and it just has so much potential.
4
+
5
+ Gut job or not, FixerUpper makes that file into the result of your dreams,
6
+ backsplash, shiplap, and all.
7
+
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem "fixer_upper"
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ $ bundle
20
+
21
+
22
+ ## Usage
23
+
24
+ ```ruby
25
+ class FixerUpperCmark
26
+ def call(text)
27
+ CommonMarker.render_html(text, :DEFAULT)
28
+ end
29
+ end
30
+
31
+ fixer_upper = FixerUpper.new
32
+ fixer_upper["md"] = FixerUpperCmark.new
33
+
34
+ fixer_upper.renovate("file.md")
35
+ # OR
36
+ fixer_upper.diy("**text**", "md")
37
+ ```
38
+
39
+
40
+ ## Development
41
+
42
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run
43
+ `rake test` to run the tests. You can also run `bin/console` for an interactive
44
+ prompt that will allow you to experiment.
45
+
46
+ To install this gem onto your local machine, run `bundle exec rake install`. To
47
+ release a new version, update the version number in `version.rb`, and then run
48
+ `bundle exec rake release`, which will create a git tag for the version, push
49
+ git commits and tags, and push the `.gem` file to
50
+ [rubygems.org][gem].
51
+
52
+
53
+ ## Contributing
54
+
55
+ Bug reports and pull requests are welcome on GitHub at
56
+ [https://github.com/zachahn/fixer_upper][git].
57
+
58
+
59
+ ## License
60
+
61
+ The gem is available as open source under the terms of the [MIT
62
+ License][license].
63
+
64
+
65
+ [gem]: https://rubygems.org
66
+ [git]: https://github.com/zachahn/fixer_upper
67
+ [license]: http://opensource.org/licenses/MIT
data/Rakefile ADDED
@@ -0,0 +1,10 @@
1
+ require "bundler/gem_tasks"
2
+ require "rake/testtask"
3
+
4
+ Rake::TestTask.new(:test) do |t|
5
+ t.libs << "test"
6
+ t.libs << "lib"
7
+ t.test_files = FileList["test/**/*_test.rb"]
8
+ end
9
+
10
+ task default: :test
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "fixer_upper"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start(__FILE__)
data/bin/rake ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rake' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require "rubygems"
16
+ require "bundler/setup"
17
+
18
+ load Gem.bin_path("rake", "rake")
data/bin/rubocop ADDED
@@ -0,0 +1,18 @@
1
+ #!/usr/bin/env ruby
2
+ # frozen_string_literal: true
3
+
4
+ #
5
+ # This file was generated by Bundler.
6
+ #
7
+ # The application 'rubocop' is installed as part of a gem, and
8
+ # this file is here to facilitate running it.
9
+ #
10
+
11
+ require "pathname"
12
+ ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
13
+ Pathname.new(__FILE__).realpath)
14
+
15
+ require "rubygems"
16
+ require "bundler/setup"
17
+
18
+ load Gem.bin_path("rubocop", "rubocop")
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,29 @@
1
+ # coding: utf-8
2
+
3
+ lib = File.expand_path("../lib", __FILE__)
4
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
+ require "fixer_upper/version"
6
+
7
+ Gem::Specification.new do |spec|
8
+ spec.name = "fixer_upper"
9
+ spec.version = FixerUpper::VERSION
10
+ spec.authors = ["Zach Ahn"]
11
+ spec.email = ["engineering@zachahn.com"]
12
+
13
+ spec.summary = "Renovate text"
14
+ spec.description = "Simple interface for template engines"
15
+ spec.license = "MIT"
16
+
17
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
18
+ f.match(%r{^(test|spec|features)/})
19
+ end
20
+ spec.bindir = "exe"
21
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.14"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "minitest", "~> 5.0"
27
+ spec.add_development_dependency "pry"
28
+ spec.add_development_dependency "rubocop"
29
+ end
@@ -0,0 +1,36 @@
1
+ require "fixer_upper/error"
2
+ require "fixer_upper/renovation"
3
+ require "fixer_upper/version"
4
+
5
+ class FixerUpper
6
+ def initialize
7
+ @engine_registry = {}
8
+ @renovation = Renovation.new(@engine_registry)
9
+ end
10
+
11
+ def []=(*keys, engine)
12
+ keys.each do |key|
13
+ @engine_registry[key] = engine
14
+ end
15
+ end
16
+
17
+ def [](key)
18
+ @engine_registry[key]
19
+ end
20
+
21
+ def renovate(filepath, contents = nil)
22
+ @renovation.renovate(filepath, contents, bang: false)
23
+ end
24
+
25
+ def renovate!(filepath, contents = nil)
26
+ @renovation.renovate(filepath, contents, bang: true)
27
+ end
28
+
29
+ def diy(text, engines)
30
+ @renovation.diy(text, engines, bang: false)
31
+ end
32
+
33
+ def diy!(text, engines)
34
+ @renovation.diy(text, engines, bang: true)
35
+ end
36
+ end
@@ -0,0 +1,6 @@
1
+ class FixerUpper
2
+ class Error < StandardError
3
+ class EngineNotFound < FixerUpper::Error
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,66 @@
1
+ class FixerUpper
2
+ class Renovation
3
+ def initialize(registry)
4
+ @registry = registry
5
+ end
6
+
7
+ def renovate(filepath, contents, bang:)
8
+ text = file_contents(filepath, contents)
9
+
10
+ diy(text, *extensions(filepath).reverse, bang: bang)
11
+ end
12
+
13
+ def diy(text, *engines, bang:)
14
+ mapped_engines = map_engines(engines, bang: bang).compact
15
+
16
+ mapped_engines.reduce(text) do |memo, engine|
17
+ engine.call(memo)
18
+ end
19
+ end
20
+
21
+ private
22
+
23
+ def map_engines(engines, bang:)
24
+ engines.map do |engine_request|
25
+ if engine_request.respond_to?(:call)
26
+ next engine_request
27
+ end
28
+
29
+ if bang
30
+ engine_or_raise(engine_request)
31
+ else
32
+ engine_or_nil(engine_request)
33
+ end
34
+ end
35
+ end
36
+
37
+ def engine_or_nil(engine_name)
38
+ @registry[engine_name]
39
+ end
40
+
41
+ def engine_or_raise(engine_name)
42
+ found_engine = @registry[engine_name]
43
+
44
+ if found_engine
45
+ file_contents
46
+ else
47
+ raise Error::EngineNotFound, "unknown engine: `#{engine_name}`"
48
+ end
49
+ end
50
+
51
+ def file_contents(filepath, contents)
52
+ if contents
53
+ contents
54
+ else
55
+ File.read(filepath)
56
+ end
57
+ end
58
+
59
+ def extensions(filepath)
60
+ filename = File.basename(filepath)
61
+ divided_by_dots = filename.split(".")
62
+
63
+ divided_by_dots[1..-1]
64
+ end
65
+ end
66
+ end
@@ -0,0 +1,3 @@
1
+ class FixerUpper
2
+ VERSION = "0.1.0".freeze
3
+ end
metadata ADDED
@@ -0,0 +1,130 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fixer_upper
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Zach Ahn
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2017-05-21 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.14'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.14'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: minitest
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '5.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '5.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: pry
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Simple interface for template engines
84
+ email:
85
+ - engineering@zachahn.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - ".gitignore"
91
+ - ".rubocop.yml"
92
+ - ".travis.yml"
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - bin/console
98
+ - bin/rake
99
+ - bin/rubocop
100
+ - bin/setup
101
+ - fixer_upper.gemspec
102
+ - lib/fixer_upper.rb
103
+ - lib/fixer_upper/error.rb
104
+ - lib/fixer_upper/renovation.rb
105
+ - lib/fixer_upper/version.rb
106
+ homepage:
107
+ licenses:
108
+ - MIT
109
+ metadata: {}
110
+ post_install_message:
111
+ rdoc_options: []
112
+ require_paths:
113
+ - lib
114
+ required_ruby_version: !ruby/object:Gem::Requirement
115
+ requirements:
116
+ - - ">="
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ required_rubygems_version: !ruby/object:Gem::Requirement
120
+ requirements:
121
+ - - ">="
122
+ - !ruby/object:Gem::Version
123
+ version: '0'
124
+ requirements: []
125
+ rubyforge_project:
126
+ rubygems_version: 2.6.8
127
+ signing_key:
128
+ specification_version: 4
129
+ summary: Renovate text
130
+ test_files: []