geny 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: 6add91eb73cf3bca67eef2bb86d8ab4e4afc06e6
4
+ data.tar.gz: 60637a783f679b4a0b473e59bd92a96a94b48890
5
+ SHA512:
6
+ metadata.gz: 74318c4fa54b0ed4337f3e6b0fb9f4ed5700dd6f49ecc98b881869f2cd7edf025f876e2192dff3df5a51c50e8f6ffa29be0584570cd64db9dc52c116efb09f70
7
+ data.tar.gz: 66f631fa5bec33843def8f4bfc57fb5f3c774a20e78d376864a3e107a5cf491460fe6691e644747e3ecd95fd7464cd48a20b488a5ba765fcf4d800535b4a7ba4
data/.gitignore ADDED
@@ -0,0 +1,11 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /_yardoc/
4
+ /coverage/
5
+ /doc/
6
+ /pkg/
7
+ /spec/reports/
8
+ /tmp/
9
+
10
+ # rspec failure tracking
11
+ .rspec_status
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --format documentation
2
+ --color
3
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ sudo: false
3
+ language: ruby
4
+ cache: bundler
5
+ rvm:
6
+ - 2.5.3
7
+ before_install: gem install bundler -v 2.0.2
data/.yardopts ADDED
@@ -0,0 +1,6 @@
1
+ --output-dir=doc/api
2
+ --embed-mixins
3
+ --protected
4
+ --no-private
5
+ --markup-provider=redcarpet
6
+ --markup=markdown
@@ -0,0 +1,74 @@
1
+ # Contributor Covenant Code of Conduct
2
+
3
+ ## Our Pledge
4
+
5
+ In the interest of fostering an open and welcoming environment, we as
6
+ contributors and maintainers pledge to making participation in our project and
7
+ our community a harassment-free experience for everyone, regardless of age, body
8
+ size, disability, ethnicity, gender identity and expression, level of experience,
9
+ nationality, personal appearance, race, religion, or sexual identity and
10
+ orientation.
11
+
12
+ ## Our Standards
13
+
14
+ Examples of behavior that contributes to creating a positive environment
15
+ include:
16
+
17
+ * Using welcoming and inclusive language
18
+ * Being respectful of differing viewpoints and experiences
19
+ * Gracefully accepting constructive criticism
20
+ * Focusing on what is best for the community
21
+ * Showing empathy towards other community members
22
+
23
+ Examples of unacceptable behavior by participants include:
24
+
25
+ * The use of sexualized language or imagery and unwelcome sexual attention or
26
+ advances
27
+ * Trolling, insulting/derogatory comments, and personal or political attacks
28
+ * Public or private harassment
29
+ * Publishing others' private information, such as a physical or electronic
30
+ address, without explicit permission
31
+ * Other conduct which could reasonably be considered inappropriate in a
32
+ professional setting
33
+
34
+ ## Our Responsibilities
35
+
36
+ Project maintainers are responsible for clarifying the standards of acceptable
37
+ behavior and are expected to take appropriate and fair corrective action in
38
+ response to any instances of unacceptable behavior.
39
+
40
+ Project maintainers have the right and responsibility to remove, edit, or
41
+ reject comments, commits, code, wiki edits, issues, and other contributions
42
+ that are not aligned to this Code of Conduct, or to ban temporarily or
43
+ permanently any contributor for other behaviors that they deem inappropriate,
44
+ threatening, offensive, or harmful.
45
+
46
+ ## Scope
47
+
48
+ This Code of Conduct applies both within project spaces and in public spaces
49
+ when an individual is representing the project or its community. Examples of
50
+ representing a project or community include using an official project e-mail
51
+ address, posting via an official social media account, or acting as an appointed
52
+ representative at an online or offline event. Representation of a project may be
53
+ further defined and clarified by project maintainers.
54
+
55
+ ## Enforcement
56
+
57
+ Instances of abusive, harassing, or otherwise unacceptable behavior may be
58
+ reported by contacting the project team at raymondzane@gmail.com. All
59
+ complaints will be reviewed and investigated and will result in a response that
60
+ is deemed necessary and appropriate to the circumstances. The project team is
61
+ obligated to maintain confidentiality with regard to the reporter of an incident.
62
+ Further details of specific enforcement policies may be posted separately.
63
+
64
+ Project maintainers who do not follow or enforce the Code of Conduct in good
65
+ faith may face temporary or permanent repercussions as determined by other
66
+ members of the project's leadership.
67
+
68
+ ## Attribution
69
+
70
+ This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
71
+ available at [http://contributor-covenant.org/version/1/4][version]
72
+
73
+ [homepage]: http://contributor-covenant.org
74
+ [version]: http://contributor-covenant.org/version/1/4/
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source "https://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in geny.gemspec
4
+ gemspec
5
+
data/Gemfile.lock ADDED
@@ -0,0 +1,69 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ geny (0.1.0)
5
+ argy (~> 0.2.2)
6
+ pastel (~> 0.7.3)
7
+ tty-file (~> 0.8.0)
8
+ tty-prompt (~> 0.20.0)
9
+
10
+ GEM
11
+ remote: https://rubygems.org/
12
+ specs:
13
+ argy (0.2.2)
14
+ diff-lcs (1.3)
15
+ docile (1.3.2)
16
+ equatable (0.6.1)
17
+ json (2.3.0)
18
+ necromancer (0.5.1)
19
+ pastel (0.7.3)
20
+ equatable (~> 0.6)
21
+ tty-color (~> 0.5)
22
+ rake (10.5.0)
23
+ rspec (3.9.0)
24
+ rspec-core (~> 3.9.0)
25
+ rspec-expectations (~> 3.9.0)
26
+ rspec-mocks (~> 3.9.0)
27
+ rspec-core (3.9.0)
28
+ rspec-support (~> 3.9.0)
29
+ rspec-expectations (3.9.0)
30
+ diff-lcs (>= 1.2.0, < 2.0)
31
+ rspec-support (~> 3.9.0)
32
+ rspec-mocks (3.9.0)
33
+ diff-lcs (>= 1.2.0, < 2.0)
34
+ rspec-support (~> 3.9.0)
35
+ rspec-support (3.9.0)
36
+ simplecov (0.17.1)
37
+ docile (~> 1.1)
38
+ json (>= 1.8, < 3)
39
+ simplecov-html (~> 0.10.0)
40
+ simplecov-html (0.10.2)
41
+ tty-color (0.5.0)
42
+ tty-cursor (0.7.0)
43
+ tty-file (0.8.0)
44
+ diff-lcs (~> 1.3)
45
+ pastel (~> 0.7.2)
46
+ tty-prompt (~> 0.18)
47
+ tty-prompt (0.20.0)
48
+ necromancer (~> 0.5.0)
49
+ pastel (~> 0.7.0)
50
+ tty-reader (~> 0.7.0)
51
+ tty-reader (0.7.0)
52
+ tty-cursor (~> 0.7)
53
+ tty-screen (~> 0.7)
54
+ wisper (~> 2.0.0)
55
+ tty-screen (0.7.0)
56
+ wisper (2.0.1)
57
+
58
+ PLATFORMS
59
+ ruby
60
+
61
+ DEPENDENCIES
62
+ bundler (~> 2.0)
63
+ geny!
64
+ rake (~> 10.0)
65
+ rspec (~> 3.0)
66
+ simplecov (~> 0.17.1)
67
+
68
+ BUNDLED WITH
69
+ 2.0.2
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2019 Ray Zane
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,66 @@
1
+ # Geny [![Build Status](https://travis-ci.org/rzane/geny.svg?branch=master)](https://travis-ci.org/rzane/geny)
2
+
3
+ A tool for building code generators.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'geny'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install geny
20
+
21
+ ## Usage
22
+
23
+ You are tired of writing the boilerplate for new React components. Let's solve that.
24
+
25
+ First, let's create a template at `.geny/react/component/templates/component.erb`:
26
+
27
+ ```javascript
28
+ import React from "react";
29
+
30
+ export const <%= name %> = props => {
31
+ return <h1><%= name ></h1>
32
+ }
33
+ ```
34
+
35
+ Next, we'll define our generator at `.geny/react/component/generator.rb`:
36
+
37
+ ```ruby
38
+ parse do
39
+ description "generate a React component"
40
+ usage "geny react:component [NAME]"
41
+ argument :name, required: true, desc: "component name"
42
+ end
43
+
44
+ invoke do
45
+ templates.copy "component.erb", "src/components/#{name}.js"
46
+ end
47
+ ```
48
+
49
+ Awesome. Run it:
50
+
51
+ $ geny react:component Logo
52
+ create src/components/Logo.js
53
+
54
+ Obviously, this is a simple example. But Geny comes with a lot of tools to help you build really great code generators with minimal effort.
55
+
56
+ ## Contributing
57
+
58
+ Bug reports and pull requests are welcome on GitHub at https://github.com/rzane/geny. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
59
+
60
+ ## License
61
+
62
+ The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
63
+
64
+ ## Code of Conduct
65
+
66
+ Everyone interacting in the Geny project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/rzane/geny/blob/master/CODE_OF_CONDUCT.md).
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "geny"
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/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
data/exe/geny ADDED
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "geny/cli"
4
+
5
+ cli = Geny::CLI.new
6
+
7
+ begin
8
+ cli.run(ARGV)
9
+ rescue Geny::Error, Argy::Error => error
10
+ cli.abort!(error.message)
11
+ end
data/geny.gemspec ADDED
@@ -0,0 +1,36 @@
1
+ lib = File.expand_path("lib", __dir__)
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
+ require "geny/version"
4
+
5
+ Gem::Specification.new do |spec|
6
+ spec.name = "geny"
7
+ spec.version = Geny::VERSION
8
+ spec.authors = ["Ray Zane"]
9
+ spec.email = ["raymondzane@gmail.com"]
10
+
11
+ spec.summary = %q{The only tool you need to build a code generator.}
12
+ spec.homepage = "https://github.com/rzane/geny"
13
+ spec.license = "MIT"
14
+
15
+ spec.metadata["source_code_uri"] = "https://github.com/rzane/geny"
16
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/github/rzane/geny"
17
+
18
+ # Specify which files should be added to the gem when it is released.
19
+ # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
21
+ `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
22
+ end
23
+ spec.bindir = "exe"
24
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
25
+ spec.require_paths = ["lib"]
26
+
27
+ spec.add_dependency "argy", "~> 0.2.2"
28
+ spec.add_dependency "pastel", "~> 0.7.3"
29
+ spec.add_dependency "tty-file", "~> 0.8.0"
30
+ spec.add_dependency "tty-prompt", "~> 0.20.0"
31
+
32
+ spec.add_development_dependency "bundler", "~> 2.0"
33
+ spec.add_development_dependency "rake", "~> 10.0"
34
+ spec.add_development_dependency "rspec", "~> 3.0"
35
+ spec.add_development_dependency "simplecov", "~> 0.17.1"
36
+ end
@@ -0,0 +1,15 @@
1
+ parse do
2
+ usage "geny new [NAME]"
3
+ description "create a new generator"
4
+ argument :name, desc: "name for your generator", required: true
5
+ end
6
+
7
+ invoke do
8
+ templates.copy "generator.rb.erb", generator_path
9
+ end
10
+
11
+ helpers do
12
+ def generator_path
13
+ File.join(".geny", *name.split(":"), Geny::Command::FILENAME)
14
+ end
15
+ end
@@ -0,0 +1,14 @@
1
+ parse do
2
+ description "a really useful generator"
3
+ usage "geny <%= name %> [MESSAGE]"
4
+ argument :message, required: true, desc: "the message to print"
5
+ option :loud, type: :boolean, aliases: ["-l"], desc: "uppercase"
6
+ end
7
+
8
+ invoke do
9
+ if loud?
10
+ ui.say message.upcase
11
+ else
12
+ ui.say message
13
+ end
14
+ end
@@ -0,0 +1,96 @@
1
+ require "tty-file"
2
+
3
+ module Geny
4
+ module Actions
5
+ # Utilities for manipulating files.
6
+ # @see https://rubydoc.info/github/piotrmurach/tty-file/master/TTY/File TTY::File
7
+ class Files
8
+ # Create a file
9
+ #
10
+ # @example
11
+ # files.create("test.txt")
12
+ # files.create("test.txt", "hello!")
13
+ # files.remove("test.txt", force: true)
14
+ def create(*args)
15
+ TTY::File.create_file(*args)
16
+ end
17
+
18
+ # Create a directory recursively
19
+ #
20
+ # @example
21
+ # files.create_dir("app/controllers")
22
+ def create_dir(*args)
23
+ TTY::File.create_dir(*args)
24
+ end
25
+
26
+ # Remove a file
27
+ #
28
+ # @example
29
+ # files.remove("tmp")
30
+ # files.remove("tmp", force: true)
31
+ def remove(*args)
32
+ TTY::File.remove_file(*args)
33
+ end
34
+
35
+ # Add a line to the top of a file
36
+ #
37
+ # @example
38
+ # files.prepend("Gemfile", "gem 'geny'")
39
+ def prepend(*args)
40
+ TTY::File.safe_prepend_to_file(*args)
41
+ end
42
+
43
+ # Add a line to the bottom of a file
44
+ #
45
+ # @example
46
+ # files.append("Gemfile", "gem 'geny'")
47
+ def append(*args)
48
+ TTY::File.safe_append_to_file(*args)
49
+ end
50
+
51
+ # Replace content in a file
52
+ #
53
+ # @example
54
+ # files.replace("Gemfile", /foo/, "bar")
55
+ def replace(*args)
56
+ TTY::File.replace_in_file(*args)
57
+ end
58
+
59
+ # Insert a line before a matching line in a file
60
+ #
61
+ # @example
62
+ # files.insert_before("Gemfile", /gem "rails"/, "gem 'geny'")
63
+ def insert_before(path, pattern, content, **opts)
64
+ opts = {before: pattern, **opts}
65
+ TTY::File.safe_inject_into_file(path, content, opts)
66
+ end
67
+
68
+ # Insert a line after a matching line in a file
69
+ #
70
+ # @example
71
+ # files.insert_after("Gemfile", /gem "rails"\n/, "gem 'geny'")
72
+ def insert_after(path, pattern, content, **opts)
73
+ opts = {after: pattern, **opts}
74
+ TTY::File.safe_inject_into_file(path, content, opts)
75
+ end
76
+
77
+ # Change the permissions of a file
78
+ #
79
+ # @example
80
+ # files.chmod("bin/test", "+x")
81
+ def chmod(path, mode, *args)
82
+ TTY::File.chmod(path, coerce_mode(mode), *args)
83
+ end
84
+
85
+ private
86
+
87
+ def coerce_mode(mode)
88
+ if mode.respond_to?(:match?) && mode.match?(/^[+-]/)
89
+ "a#{mode}"
90
+ else
91
+ mode
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,53 @@
1
+ require "geny/error"
2
+
3
+ module Geny
4
+ module Actions
5
+ # Utilities for interacting with a git repo
6
+ class Git
7
+ # Create a new Git
8
+ # @param shell [Shell]
9
+ def initialize(shell:)
10
+ @shell = shell
11
+ end
12
+
13
+ # Initialize a new git repo
14
+ # @raise [ExitError]
15
+ #
16
+ # @example
17
+ # git.init
18
+ def init(**opts)
19
+ @shell.run("git", "init", out: File::NULL, **opts)
20
+ end
21
+
22
+ # Stage files to be committed
23
+ # @param files [Array<String>]
24
+ # @raise [ExitError]
25
+ #
26
+ # @example
27
+ # git.add
28
+ # git.add files: ["Gemfile"]
29
+ def add(files: ["."], **opts)
30
+ @shell.run("git", "add", *files, out: File::NULL, **opts)
31
+ end
32
+
33
+ # Commit staged files
34
+ # @param message [String]
35
+ # @raise [ExitError]
36
+ #
37
+ # @example
38
+ # git.commit message: "First commit"
39
+ def commit(message:, **opts)
40
+ @shell.run("git", "commit", "-m", message, out: File::NULL, **opts)
41
+ end
42
+
43
+ # Get the path to the current git repo
44
+ # @raise [ExitError]
45
+ #
46
+ # @example
47
+ # git.repo_path #=> "/path/to/repo"
48
+ def repo_path(**opts)
49
+ @shell.capture("git", "rev-parse", "--show-toplevel", **opts)
50
+ end
51
+ end
52
+ end
53
+ end
@@ -0,0 +1,62 @@
1
+ require "open3"
2
+ require "geny/error"
3
+
4
+ module Geny
5
+ module Actions
6
+ # Utilities for executing shell commands
7
+ class Shell
8
+ # Create a new shell
9
+ # @param ui [UI]
10
+ def initialize(ui:)
11
+ @ui = ui
12
+ end
13
+
14
+ # Run a shell command and return it's output
15
+ # @raise [ExitError] when the command exits with a non-zero status
16
+ # @return [String]
17
+ #
18
+ # @example
19
+ # shell.capture("echo", "hello") #=> "hello"
20
+ def capture(*args, **opts)
21
+ cmd = build_command(*args, **opts)
22
+ cmd_str = stringify_command(args)
23
+ out, _err, status = Open3.capture3(*cmd)
24
+ assert_success!(status, cmd_str)
25
+ out.chomp
26
+ rescue Errno::ENOENT
27
+ raise ExitError.new(command: cmd_str, code: 127)
28
+ end
29
+
30
+ # Run a shell command
31
+ # @raise [ExitError] when the command exits with a non-zero status
32
+ #
33
+ # @example
34
+ # shell.capture("echo", "hello") # prints "hello"
35
+ def run(*args, verbose: true, **opts)
36
+ cmd = build_command(*args, **opts)
37
+ cmd_str = stringify_command(args)
38
+
39
+ @ui.status("run", cmd_str) if verbose
40
+
41
+ Kernel.system(*cmd)
42
+ assert_success!($?, cmd_str)
43
+ end
44
+
45
+ private
46
+
47
+ def build_command(*args, env: nil, **opts)
48
+ [*env, *args, **opts]
49
+ end
50
+
51
+ def stringify_command(args)
52
+ args.map { |arg| arg.match?(/\s/) ? arg.inspect : arg }.join(" ")
53
+ end
54
+
55
+ def assert_success!(status, cmd)
56
+ unless status.success?
57
+ raise ExitError.new(command: cmd, code: status.exitstatus)
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,68 @@
1
+ require "tty-file"
2
+ require "geny/context/view"
3
+
4
+ module Geny
5
+ module Actions
6
+ # Utilities for rendering and copying templates.
7
+ # @see https://rubydoc.info/github/piotrmurach/tty-file/master/TTY/File TTY::File
8
+ class Templates
9
+ # Creates a new instance
10
+ # @param root [String] the root path where templates live
11
+ # @param view [View] a view that exposes locals and helpers
12
+ def initialize(root:, view:)
13
+ @root = root
14
+ @view = view
15
+ end
16
+
17
+ # Copy a template file. The file will be evaluated with ERB.
18
+ # All command-line options and helper methods are available in
19
+ # the template.
20
+ #
21
+ # @example
22
+ # templates.copy("hello.erb", "hello.txt")
23
+ # templates.copy("hello.erb", "hello.txt", locals: {name: "world"})
24
+ def copy(source, *args, **opts)
25
+ source = expand_path(source)
26
+ context, opts = build_context(opts)
27
+ TTY::File.copy_file(source, *args, context: context, **opts)
28
+ end
29
+
30
+ # Copy a template directory. All files will be evaluated with ERB.
31
+ # All command-line options and helper methods are available in
32
+ # the template.
33
+ #
34
+ # @example
35
+ # templates.copy_dir("boilerplate", output)
36
+ # templates.copy_dir("boilerplate", output, locals: {name: "world"})
37
+ def copy_dir(source, *args, **opts)
38
+ source = expand_path(source)
39
+ context, opts = build_context(opts)
40
+ TTY::File.copy_dir(source, *args, context: context, **opts)
41
+ end
42
+
43
+ # Render an ERB template. All command-line options and helper
44
+ # methods are available in the template.
45
+ #
46
+ # @example
47
+ # templates.render("hello.erb")
48
+ # templates.render("hello.erb", locals: {name: "world"})
49
+ def render(path, **opts)
50
+ path = expand_path(path)
51
+ input = File.binread(path)
52
+ context, _opts = build_context(opts)
53
+ erb = ERB.new(input, nil, "-", "@output_buffer")
54
+ erb.result(context.instance_eval("binding"))
55
+ end
56
+
57
+ private
58
+
59
+ def build_context(locals: {}, **opts)
60
+ [@view.merge(locals), opts]
61
+ end
62
+
63
+ def expand_path(path)
64
+ File.expand_path(path, @root)
65
+ end
66
+ end
67
+ end
68
+ end