toys 0.12.1 → 0.13.1
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 +4 -4
- data/.yardopts +2 -0
- data/CHANGELOG.md +44 -0
- data/LICENSE.md +1 -1
- data/README.md +7 -4
- data/builtins/system/git-cache.rb +238 -0
- data/builtins/system/test.rb +37 -2
- data/core-docs/toys/acceptor.rb +432 -0
- data/core-docs/toys/arg_parser.rb +397 -0
- data/core-docs/toys/cli.rb +493 -0
- data/core-docs/toys/compat.rb +2 -0
- data/core-docs/toys/completion.rb +329 -0
- data/core-docs/toys/context.rb +321 -0
- data/core-docs/toys/core.rb +14 -0
- data/core-docs/toys/dsl/base.rb +56 -0
- data/core-docs/toys/dsl/flag.rb +261 -0
- data/core-docs/toys/dsl/flag_group.rb +259 -0
- data/core-docs/toys/dsl/internal.rb +4 -0
- data/core-docs/toys/dsl/positional_arg.rb +139 -0
- data/core-docs/toys/dsl/tool.rb +1530 -0
- data/core-docs/toys/errors.rb +93 -0
- data/core-docs/toys/flag.rb +549 -0
- data/core-docs/toys/flag_group.rb +186 -0
- data/core-docs/toys/input_file.rb +8 -0
- data/core-docs/toys/loader.rb +222 -0
- data/core-docs/toys/middleware.rb +295 -0
- data/core-docs/toys/mixin.rb +142 -0
- data/core-docs/toys/module_lookup.rb +75 -0
- data/core-docs/toys/positional_arg.rb +145 -0
- data/core-docs/toys/settings.rb +507 -0
- data/core-docs/toys/source_info.rb +127 -0
- data/core-docs/toys/standard_middleware/add_verbosity_flags.rb +49 -0
- data/core-docs/toys/standard_middleware/apply_config.rb +24 -0
- data/core-docs/toys/standard_middleware/handle_usage_errors.rb +33 -0
- data/core-docs/toys/standard_middleware/set_default_descriptions.rb +222 -0
- data/core-docs/toys/standard_middleware/show_help.rb +190 -0
- data/core-docs/toys/standard_middleware/show_root_version.rb +45 -0
- data/core-docs/toys/standard_mixins/bundler.rb +83 -0
- data/core-docs/toys/standard_mixins/exec.rb +645 -0
- data/core-docs/toys/standard_mixins/fileutils.rb +18 -0
- data/core-docs/toys/standard_mixins/gems.rb +48 -0
- data/core-docs/toys/standard_mixins/git_cache.rb +41 -0
- data/core-docs/toys/standard_mixins/highline.rb +133 -0
- data/core-docs/toys/standard_mixins/terminal.rb +135 -0
- data/core-docs/toys/standard_mixins/xdg.rb +49 -0
- data/core-docs/toys/template.rb +112 -0
- data/core-docs/toys/tool_definition.rb +926 -0
- data/core-docs/toys/utils/completion_engine.rb +49 -0
- data/core-docs/toys/utils/exec.rb +721 -0
- data/core-docs/toys/utils/gems.rb +185 -0
- data/core-docs/toys/utils/git_cache.rb +353 -0
- data/core-docs/toys/utils/help_text.rb +134 -0
- data/core-docs/toys/utils/terminal.rb +310 -0
- data/core-docs/toys/utils/xdg.rb +253 -0
- data/core-docs/toys/wrappable_string.rb +120 -0
- data/core-docs/toys-core.rb +63 -0
- data/docs/guide.md +497 -156
- data/lib/toys/standard_cli.rb +50 -36
- data/lib/toys/templates/clean.rb +18 -0
- data/lib/toys/templates/gem_build.rb +24 -0
- data/lib/toys/templates/minitest.rb +21 -0
- data/lib/toys/templates/rake.rb +23 -3
- data/lib/toys/templates/rdoc.rb +29 -0
- data/lib/toys/templates/rspec.rb +32 -4
- data/lib/toys/templates/rubocop.rb +14 -1
- data/lib/toys/templates/yardoc.rb +55 -0
- data/lib/toys/testing.rb +186 -109
- data/lib/toys/version.rb +1 -1
- data/lib/toys.rb +4 -2
- metadata +56 -6
@@ -0,0 +1,48 @@
|
|
1
|
+
module Toys
|
2
|
+
module StandardMixins
|
3
|
+
##
|
4
|
+
# **_Defined in the toys-core gem_**
|
5
|
+
#
|
6
|
+
# Provides methods for installing and activating third-party gems. When
|
7
|
+
# this mixin is included, it provides a `gem` method that has the same
|
8
|
+
# effect as {Toys::Utils::Gems#activate}, so you can ensure a gem is
|
9
|
+
# present when running a tool. A `gem` directive is likewise added to the
|
10
|
+
# tool DSL itself, so you can also ensure a gem is present when defining a
|
11
|
+
# tool.
|
12
|
+
#
|
13
|
+
# You may make these methods available to your tool by including the
|
14
|
+
# following directive in your tool configuration:
|
15
|
+
#
|
16
|
+
# include :gems
|
17
|
+
#
|
18
|
+
# If you pass additional options to the include directive, those are used
|
19
|
+
# to initialize settings for the gem install process. For example:
|
20
|
+
#
|
21
|
+
# include :gems, on_missing: :error
|
22
|
+
#
|
23
|
+
# See {Toys::Utils::Gems#initialize} for a list of supported options.
|
24
|
+
#
|
25
|
+
module Gems
|
26
|
+
include Mixin
|
27
|
+
|
28
|
+
##
|
29
|
+
# A tool-wide instance of {Toys::Utils::Gems}.
|
30
|
+
# @return [Toys::Utils::Gems]
|
31
|
+
#
|
32
|
+
def gems
|
33
|
+
# Source available in the toys-core gem
|
34
|
+
end
|
35
|
+
|
36
|
+
##
|
37
|
+
# Activate the given gem.
|
38
|
+
#
|
39
|
+
# @param name [String] Name of the gem
|
40
|
+
# @param requirements [String...] Version requirements
|
41
|
+
# @return [void]
|
42
|
+
#
|
43
|
+
def gem(name, *requirements)
|
44
|
+
# Source available in the toys-core gem
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,41 @@
|
|
1
|
+
module Toys
|
2
|
+
module StandardMixins
|
3
|
+
##
|
4
|
+
# **_Defined in the toys-core gem_**
|
5
|
+
#
|
6
|
+
# A mixin that provides a git cache.
|
7
|
+
#
|
8
|
+
# This mixin provides an instance of {Toys::Utils::GitCache}, providing
|
9
|
+
# cached access to files from a remote git repo.
|
10
|
+
#
|
11
|
+
# Example usage:
|
12
|
+
#
|
13
|
+
# include :git_cache
|
14
|
+
#
|
15
|
+
# def run
|
16
|
+
# # Pull and cache the HEAD commit from the Toys repo.
|
17
|
+
# dir = git_cache.find("https://github.com/dazuma/toys.git")
|
18
|
+
# # Display the contents of the readme file.
|
19
|
+
# puts File.read(File.join(dir, "README.md"))
|
20
|
+
# end
|
21
|
+
#
|
22
|
+
module GitCache
|
23
|
+
include Mixin
|
24
|
+
|
25
|
+
##
|
26
|
+
# Context key for the GitCache object.
|
27
|
+
# @return [Object]
|
28
|
+
#
|
29
|
+
KEY = ::Object.new.freeze
|
30
|
+
|
31
|
+
##
|
32
|
+
# Access the builtin GitCache.
|
33
|
+
#
|
34
|
+
# @return [Toys::Utils::GitCache]
|
35
|
+
#
|
36
|
+
def git_cache
|
37
|
+
# Source available in the toys-core gem
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
@@ -0,0 +1,133 @@
|
|
1
|
+
module Toys
|
2
|
+
module StandardMixins
|
3
|
+
##
|
4
|
+
# **_Defined in the toys-core gem_**
|
5
|
+
#
|
6
|
+
# A mixin that provides access to the capabilities of the highline gem.
|
7
|
+
#
|
8
|
+
# This mixin requires the highline gem, version 2.0 or later. It will
|
9
|
+
# attempt to install the gem if it is not available.
|
10
|
+
#
|
11
|
+
# You may make these methods available to your tool by including the
|
12
|
+
# following directive in your tool configuration:
|
13
|
+
#
|
14
|
+
# include :highline
|
15
|
+
#
|
16
|
+
# A HighLine object will then be available by calling the {#highline}
|
17
|
+
# method. For information on using this object, see the
|
18
|
+
# [Highline documentation](https://www.rubydoc.info/gems/highline). Some of
|
19
|
+
# the most common HighLine methods, such as `say`, are also mixed into the
|
20
|
+
# tool and can be called directly.
|
21
|
+
#
|
22
|
+
# You can configure the HighLine object by passing options to the `include`
|
23
|
+
# directive. For example:
|
24
|
+
#
|
25
|
+
# include :highline, my_stdin, my_stdout
|
26
|
+
#
|
27
|
+
# The arguments will be passed on to the
|
28
|
+
# [HighLine constructor](https://www.rubydoc.info/gems/highline/HighLine:initialize).
|
29
|
+
#
|
30
|
+
module Highline
|
31
|
+
include Mixin
|
32
|
+
|
33
|
+
##
|
34
|
+
# Context key for the highline object.
|
35
|
+
# @return [Object]
|
36
|
+
#
|
37
|
+
KEY = ::Object.new.freeze
|
38
|
+
|
39
|
+
##
|
40
|
+
# A tool-wide [HighLine](https://www.rubydoc.info/gems/highline/HighLine)
|
41
|
+
# instance
|
42
|
+
# @return [::HighLine]
|
43
|
+
#
|
44
|
+
def highline
|
45
|
+
# Source available in the toys-core gem
|
46
|
+
end
|
47
|
+
|
48
|
+
##
|
49
|
+
# Calls [HighLine#agree](https://www.rubydoc.info/gems/highline/HighLine:agree)
|
50
|
+
#
|
51
|
+
def agree(*args, &block)
|
52
|
+
# Source available in the toys-core gem
|
53
|
+
end
|
54
|
+
|
55
|
+
##
|
56
|
+
# Calls [HighLine#ask](https://www.rubydoc.info/gems/highline/HighLine:ask)
|
57
|
+
#
|
58
|
+
def ask(*args, &block)
|
59
|
+
# Source available in the toys-core gem
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Calls [HighLine#choose](https://www.rubydoc.info/gems/highline/HighLine:choose)
|
64
|
+
#
|
65
|
+
def choose(*args, &block)
|
66
|
+
# Source available in the toys-core gem
|
67
|
+
end
|
68
|
+
|
69
|
+
##
|
70
|
+
# Calls [HighLine#list](https://www.rubydoc.info/gems/highline/HighLine:list)
|
71
|
+
#
|
72
|
+
def list(*args, &block)
|
73
|
+
# Source available in the toys-core gem
|
74
|
+
end
|
75
|
+
|
76
|
+
##
|
77
|
+
# Calls [HighLine#say](https://www.rubydoc.info/gems/highline/HighLine:say)
|
78
|
+
#
|
79
|
+
def say(*args, &block)
|
80
|
+
# Source available in the toys-core gem
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# Calls [HighLine#indent](https://www.rubydoc.info/gems/highline/HighLine:indent)
|
85
|
+
#
|
86
|
+
def indent(*args, &block)
|
87
|
+
# Source available in the toys-core gem
|
88
|
+
end
|
89
|
+
|
90
|
+
##
|
91
|
+
# Calls [HighLine#newline](https://www.rubydoc.info/gems/highline/HighLine:newline)
|
92
|
+
#
|
93
|
+
def newline
|
94
|
+
# Source available in the toys-core gem
|
95
|
+
end
|
96
|
+
|
97
|
+
##
|
98
|
+
# Calls [HighLine#puts](https://www.rubydoc.info/gems/highline/HighLine:puts)
|
99
|
+
#
|
100
|
+
def puts(*args)
|
101
|
+
# Source available in the toys-core gem
|
102
|
+
end
|
103
|
+
|
104
|
+
##
|
105
|
+
# Calls [HighLine#color](https://www.rubydoc.info/gems/highline/HighLine:color)
|
106
|
+
#
|
107
|
+
def color(*args)
|
108
|
+
# Source available in the toys-core gem
|
109
|
+
end
|
110
|
+
|
111
|
+
##
|
112
|
+
# Calls [HighLine#color_code](https://www.rubydoc.info/gems/highline/HighLine:color_code)
|
113
|
+
#
|
114
|
+
def color_code(*args)
|
115
|
+
# Source available in the toys-core gem
|
116
|
+
end
|
117
|
+
|
118
|
+
##
|
119
|
+
# Calls [HighLine#uncolor](https://www.rubydoc.info/gems/highline/HighLine:uncolor)
|
120
|
+
#
|
121
|
+
def uncolor(*args)
|
122
|
+
# Source available in the toys-core gem
|
123
|
+
end
|
124
|
+
|
125
|
+
##
|
126
|
+
# Calls [HighLine#new_scope](https://www.rubydoc.info/gems/highline/HighLine:new_scope)
|
127
|
+
#
|
128
|
+
def new_scope
|
129
|
+
# Source available in the toys-core gem
|
130
|
+
end
|
131
|
+
end
|
132
|
+
end
|
133
|
+
end
|
@@ -0,0 +1,135 @@
|
|
1
|
+
module Toys
|
2
|
+
module StandardMixins
|
3
|
+
##
|
4
|
+
# **_Defined in the toys-core gem_**
|
5
|
+
#
|
6
|
+
# A mixin that provides a simple terminal. It includes a set of methods
|
7
|
+
# that produce styled output, get user input, and otherwise interact with
|
8
|
+
# the user's terminal. This mixin is not as richly featured as other mixins
|
9
|
+
# such as Highline, but it has no gem dependencies so is ideal for basic
|
10
|
+
# cases.
|
11
|
+
#
|
12
|
+
# You may make these methods available to your tool by including the
|
13
|
+
# following directive in your tool configuration:
|
14
|
+
#
|
15
|
+
# include :terminal
|
16
|
+
#
|
17
|
+
# A Terminal object will then be available by calling the {#terminal}
|
18
|
+
# method. For information on using this object, see the documentation for
|
19
|
+
# {Toys::Utils::Terminal}. Some of the most useful methods are also mixed
|
20
|
+
# into the tool and can be called directly.
|
21
|
+
#
|
22
|
+
# You can configure the Terminal object by passing options to the `include`
|
23
|
+
# directive. For example:
|
24
|
+
#
|
25
|
+
# include :terminal, styled: true
|
26
|
+
#
|
27
|
+
# The arguments will be passed on to {Toys::Utils::Terminal#initialize}.
|
28
|
+
#
|
29
|
+
module Terminal
|
30
|
+
include Mixin
|
31
|
+
|
32
|
+
##
|
33
|
+
# Context key for the terminal object.
|
34
|
+
# @return [Object]
|
35
|
+
#
|
36
|
+
KEY = ::Object.new.freeze
|
37
|
+
|
38
|
+
##
|
39
|
+
# A tool-wide terminal instance
|
40
|
+
# @return [Toys::Utils::Terminal]
|
41
|
+
#
|
42
|
+
def terminal
|
43
|
+
# Source available in the toys-core gem
|
44
|
+
end
|
45
|
+
|
46
|
+
##
|
47
|
+
# Write a line, appending a newline if one is not already present.
|
48
|
+
#
|
49
|
+
# @see Toys::Utils::Terminal#puts
|
50
|
+
#
|
51
|
+
# @param str [String] The line to write
|
52
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
53
|
+
# entire line.
|
54
|
+
# @return [self]
|
55
|
+
#
|
56
|
+
def puts(str = "", *styles)
|
57
|
+
# Source available in the toys-core gem
|
58
|
+
end
|
59
|
+
alias say puts
|
60
|
+
|
61
|
+
##
|
62
|
+
# Write a partial line without appending a newline.
|
63
|
+
#
|
64
|
+
# @see Toys::Utils::Terminal#write
|
65
|
+
#
|
66
|
+
# @param str [String] The line to write
|
67
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
68
|
+
# partial line.
|
69
|
+
# @return [self]
|
70
|
+
#
|
71
|
+
def write(str = "", *styles)
|
72
|
+
# Source available in the toys-core gem
|
73
|
+
end
|
74
|
+
|
75
|
+
##
|
76
|
+
# Ask a question and get a response.
|
77
|
+
#
|
78
|
+
# @see Toys::Utils::Terminal#ask
|
79
|
+
#
|
80
|
+
# @param prompt [String] Required prompt string.
|
81
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
82
|
+
# prompt.
|
83
|
+
# @param default [String,nil] Default value, or `nil` for no default.
|
84
|
+
# Uses `nil` if not specified.
|
85
|
+
# @param trailing_text [:default,String,nil] Trailing text appended to
|
86
|
+
# the prompt, `nil` for none, or `:default` to show the default.
|
87
|
+
# @return [String]
|
88
|
+
#
|
89
|
+
def ask(prompt, *styles, default: nil, trailing_text: :default)
|
90
|
+
# Source available in the toys-core gem
|
91
|
+
end
|
92
|
+
|
93
|
+
##
|
94
|
+
# Confirm with the user.
|
95
|
+
#
|
96
|
+
# @see Toys::Utils::Terminal#confirm
|
97
|
+
#
|
98
|
+
# @param prompt [String] Prompt string. Defaults to `"Proceed?"`.
|
99
|
+
# @param styles [Symbol,String,Array<Integer>...] Styles to apply to the
|
100
|
+
# prompt.
|
101
|
+
# @param default [Boolean,nil] Default value, or `nil` for no default.
|
102
|
+
# Uses `nil` if not specified.
|
103
|
+
# @return [Boolean]
|
104
|
+
#
|
105
|
+
def confirm(prompt = "Proceed?", *styles, default: nil)
|
106
|
+
# Source available in the toys-core gem
|
107
|
+
end
|
108
|
+
|
109
|
+
##
|
110
|
+
# Display a spinner during a task. You should provide a block that
|
111
|
+
# performs the long-running task. While the block is executing, a
|
112
|
+
# spinner will be displayed.
|
113
|
+
#
|
114
|
+
# @see Toys::Utils::Terminal#spinner
|
115
|
+
#
|
116
|
+
# @param leading_text [String] Optional leading string to display to the
|
117
|
+
# left of the spinner. Default is the empty string.
|
118
|
+
# @param frame_length [Float] Length of a single frame, in seconds.
|
119
|
+
# Defaults to {Toys::Utils::Terminal::DEFAULT_SPINNER_FRAME_LENGTH}.
|
120
|
+
# @param frames [Array<String>] An array of frames. Defaults to
|
121
|
+
# {Toys::Utils::Terminal::DEFAULT_SPINNER_FRAMES}.
|
122
|
+
# @param style [Symbol,Array<Symbol>] A terminal style or array of styles
|
123
|
+
# to apply to all frames in the spinner. Defaults to empty,
|
124
|
+
# @param final_text [String] Optional final string to display when the
|
125
|
+
# spinner is complete. Default is the empty string. A common practice
|
126
|
+
# is to set this to newline.
|
127
|
+
# @return [Object] The return value of the block.
|
128
|
+
#
|
129
|
+
def spinner(leading_text: "", final_text: "",
|
130
|
+
frame_length: nil, frames: nil, style: nil, &block)
|
131
|
+
# Source available in the toys-core gem
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
135
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
module Toys
|
2
|
+
module StandardMixins
|
3
|
+
##
|
4
|
+
# **_Defined in the toys-core gem_**
|
5
|
+
#
|
6
|
+
# A mixin that provides tools for working with the XDG Base Directory
|
7
|
+
# Specification.
|
8
|
+
#
|
9
|
+
# This mixin provides an instance of {Toys::Utils::XDG}, which includes
|
10
|
+
# utility methods that locate base directories and search paths for
|
11
|
+
# application state, configuration, caches, and other data, according to
|
12
|
+
# the [XDG Base Directory Spec version
|
13
|
+
# 0.8](https://specifications.freedesktop.org/basedir-spec/0.8/).
|
14
|
+
#
|
15
|
+
# Example usage:
|
16
|
+
#
|
17
|
+
# include :xdg
|
18
|
+
#
|
19
|
+
# def run
|
20
|
+
# # Get config file paths, in order from most to least inportant
|
21
|
+
# config_files = xdg.lookup_config("my-config.toml")
|
22
|
+
# config_files.each { |path| read_my_config(path) }
|
23
|
+
# end
|
24
|
+
#
|
25
|
+
module XDG
|
26
|
+
include Mixin
|
27
|
+
|
28
|
+
##
|
29
|
+
# Context key for the XDG object.
|
30
|
+
# @return [Object]
|
31
|
+
#
|
32
|
+
KEY = ::Object.new.freeze
|
33
|
+
|
34
|
+
##
|
35
|
+
# Access XDG utility methods.
|
36
|
+
#
|
37
|
+
# @return [Toys::Utils::XDG]
|
38
|
+
#
|
39
|
+
def xdg
|
40
|
+
# Source available in the toys-core gem
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
##
|
45
|
+
# An alternate name for the {XDG} module
|
46
|
+
#
|
47
|
+
Xdg = XDG
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
module Toys
|
2
|
+
##
|
3
|
+
# **_Defined in the toys-core gem_**
|
4
|
+
#
|
5
|
+
# A template definition. Template classes should include this module.
|
6
|
+
#
|
7
|
+
# A template is a configurable set of DSL code that can be run in a toys
|
8
|
+
# configuration to automate tool defintion. For example, toys provides a
|
9
|
+
# "minitest" template that generates a "test" tool that invokes minitest.
|
10
|
+
# Templates will often support configuration; for example the minitest
|
11
|
+
# template lets you configure the paths to the test files.
|
12
|
+
#
|
13
|
+
# ### Usage
|
14
|
+
#
|
15
|
+
# To create a template, define a class and include this module.
|
16
|
+
# The class defines the "configuration" of the template. If your template
|
17
|
+
# has options/parameters, you should provide a constructor, and methods
|
18
|
+
# appropriate to edit those options. The arguments given to the
|
19
|
+
# {Toys::DSL::Tool#expand} method are passed to your constructor, and your
|
20
|
+
# template object is passed to any block given to {Toys::DSL::Tool#expand}.
|
21
|
+
#
|
22
|
+
# Next, in your template class, call the `on_expand` method, which is defined
|
23
|
+
# in {Toys::Template::ClassMethods#on_expand}. Pass this a block which
|
24
|
+
# defines the implementation of the template. Effectively, the contents of
|
25
|
+
# this block are "inserted" into the user's configuration. The template
|
26
|
+
# object is passed to the block so you have access to the template options.
|
27
|
+
#
|
28
|
+
# ### Example
|
29
|
+
#
|
30
|
+
# This is a simple template that generates a "hello" tool. The tool simply
|
31
|
+
# prints a `"Hello, #{name}!"` greeting. The name is set as a template
|
32
|
+
# option; it is defined when the template is expanded in a toys
|
33
|
+
# configuration.
|
34
|
+
#
|
35
|
+
# # Define a template by creating a class that includes Toys::Template.
|
36
|
+
# class MyHelloTemplate
|
37
|
+
# include Toys::Template
|
38
|
+
#
|
39
|
+
# # A user of the template may pass an optional name as a parameter to
|
40
|
+
# # `expand`, or leave it as the default of "world".
|
41
|
+
# def initialize(name: "world")
|
42
|
+
# @name = name
|
43
|
+
# end
|
44
|
+
#
|
45
|
+
# # The template is passed to the expand block, so a user of the
|
46
|
+
# # template may also call this method to set the name.
|
47
|
+
# attr_accessor :name
|
48
|
+
#
|
49
|
+
# # The following block is inserted when the template is expanded.
|
50
|
+
# on_expand do |template|
|
51
|
+
# desc "Prints a greeting to #{template.name}"
|
52
|
+
# tool "templated-greeting" do
|
53
|
+
# to_run do
|
54
|
+
# puts "Hello, #{template.name}!"
|
55
|
+
# end
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
#
|
60
|
+
# Now you can use the template in your `.toys.rb` file like this:
|
61
|
+
#
|
62
|
+
# expand(MyHelloTemplate, name: "rubyists")
|
63
|
+
#
|
64
|
+
# or alternately:
|
65
|
+
#
|
66
|
+
# expand(MyHelloTemplate) do |template|
|
67
|
+
# template.name = "rubyists"
|
68
|
+
# end
|
69
|
+
#
|
70
|
+
# And it will create a tool called "templated-greeting".
|
71
|
+
#
|
72
|
+
module Template
|
73
|
+
##
|
74
|
+
# Create a template class with the given block.
|
75
|
+
#
|
76
|
+
# @param block [Proc] Defines the template class.
|
77
|
+
# @return [Class]
|
78
|
+
#
|
79
|
+
def self.create(&block)
|
80
|
+
# Source available in the toys-core gem
|
81
|
+
end
|
82
|
+
|
83
|
+
##
|
84
|
+
# **_Defined in the toys-core gem_**
|
85
|
+
#
|
86
|
+
# Class methods that will be added to a template class.
|
87
|
+
#
|
88
|
+
module ClassMethods
|
89
|
+
##
|
90
|
+
# Define how to expand this template. The given block is passed the
|
91
|
+
# template object, and is evaluated in the tool class. It should invoke
|
92
|
+
# directives to create tools and other objects.
|
93
|
+
#
|
94
|
+
# @param block [Proc] The expansion of this template.
|
95
|
+
# @return [self]
|
96
|
+
#
|
97
|
+
def on_expand(&block)
|
98
|
+
# Source available in the toys-core gem
|
99
|
+
end
|
100
|
+
alias to_expand on_expand
|
101
|
+
|
102
|
+
##
|
103
|
+
# The template expansion proc. This proc is passed the template object,
|
104
|
+
# and is evaluted in the tool class. It should invoke directives to
|
105
|
+
# create tools and other objects.
|
106
|
+
#
|
107
|
+
# @return [Proc] The expansion of this template.
|
108
|
+
#
|
109
|
+
attr_accessor :expansion
|
110
|
+
end
|
111
|
+
end
|
112
|
+
end
|