okay 10.0.0 → 11.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +20 -0
- data/lib/okay/simple_opts.rb +23 -20
- data/lib/okay/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 644512c8f6e9711f699eb2dcc1b140afb21942035549aaf78c6324205d17ca42
|
4
|
+
data.tar.gz: 5401ca57ba69b8a35b3e37acbf52645cb9571aa0fa0a3608be07b160952550db
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6f41a2ede17a3af2d5c8dae9e3f26747c3c3739a3be23f619d934247eac3a8a2600125561224d9b263d23f49c633afc40dfc588ff9307ce273edf6221472b9f9
|
7
|
+
data.tar.gz: d9b54ddcd04277369c0aa0ea80c23a1157c84d9f8c3555314446f1a981abf0eba2245968dc5ed16cfb4cd36b220be5c7c140f5fb08ff9edfbe70f8cb743f685c
|
data/README.md
CHANGED
@@ -108,6 +108,26 @@ response.body.from_json
|
|
108
108
|
|
109
109
|
```
|
110
110
|
|
111
|
+
### Template Engine
|
112
|
+
|
113
|
+
Okay also provides a basic templating engine.
|
114
|
+
|
115
|
+
It is literally just a wrapper around `Kernel.format()` and `Pathname`.
|
116
|
+
|
117
|
+
Assuming a `./templates/example.html` containing: `a %{foo} c %{bar} e`
|
118
|
+
|
119
|
+
```ruby
|
120
|
+
require "okay/template"
|
121
|
+
|
122
|
+
template = Okay::Template.new("./templates/")
|
123
|
+
template.apply("example.html", {foo: "b", bar: "d"}) #=> "a b c d e"
|
124
|
+
```
|
125
|
+
|
126
|
+
### SimpleOpts (OptionParser improvements)
|
127
|
+
|
128
|
+
See the [example usage in
|
129
|
+
HowIs](https://github.com/how-is/how_is/blob/ad81620/lib/how_is/cli.rb#L39-L74).
|
130
|
+
|
111
131
|
## Development
|
112
132
|
|
113
133
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/okay/simple_opts.rb
CHANGED
@@ -1,28 +1,31 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require "okay/version"
|
3
4
|
require "optparse"
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
6
|
+
module Okay
|
7
|
+
##
|
8
|
+
# An OptionParser wrapper providing a few convenience functions.
|
9
|
+
class SimpleOpts < OptionParser
|
10
|
+
def initialize(*args, defaults: nil)
|
11
|
+
super(*args)
|
12
|
+
@okay_options = defaults || {}
|
13
|
+
end
|
12
14
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
15
|
+
# simple(..., :a)
|
16
|
+
# simple(..., :b)
|
17
|
+
# ==
|
18
|
+
# options = {}
|
19
|
+
# on(...) { |val| options[:a] = val }
|
20
|
+
# on(...) { |val| options[:b] = val }
|
21
|
+
def simple(*args)
|
22
|
+
key = args.pop
|
23
|
+
on(*args) { |*x| @okay_options[key] = x[0] }
|
24
|
+
end
|
23
25
|
|
24
|
-
|
25
|
-
|
26
|
-
|
26
|
+
def parse(args)
|
27
|
+
parse!(args.dup)
|
28
|
+
@okay_options
|
29
|
+
end
|
27
30
|
end
|
28
31
|
end
|
data/lib/okay/version.rb
CHANGED