Skip to content

Commit dab78e5

Browse files
authored
Merge pull request #506 from DannyBen/add/render-options
Add `Renderable#render_options` for `argument/case.gtx`
2 parents 35b9eb3 + ed44179 commit dab78e5

File tree

6 files changed

+40
-37
lines changed

6 files changed

+40
-37
lines changed

lib/bashly/concerns/renderable.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,10 @@
22

33
module Bashly
44
module Renderable
5-
def render(view)
5+
attr_reader :render_options
6+
7+
def render(view, render_options = {})
8+
@render_options = render_options
69
GTX.render_file view_path(view), context: binding, filename: "#{views_subfolder}.#{view}"
710
end
811

lib/bashly/views/argument/case.gtx

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
= view_marker
2+
3+
condition = render_options[:index].zero? ? 'if' : 'elif'
4+
> {{ condition }} [[ -z ${args['{{ name }}']+x} ]]; then
5+
> args['{{ name }}']=$1
6+
> shift
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
= view_marker
2+
3+
condition = render_options[:index].zero? ? 'if' : 'elif'
4+
5+
if render_options[:index] == 0
6+
> escaped="$(printf '%q' "$1")"
7+
end
8+
9+
> {{ condition }} [[ -z ${args['{{ name }}']+x} ]]; then
10+
if repeatable
11+
> args['{{ name }}']="$escaped"
12+
if unique
13+
> unique_lookup["{{ name }}:$escaped"]=1
14+
> elif [[ -z "${unique_lookup["{{ name }}:$escaped"]:-}" ]]; then
15+
> args['{{ name }}']="${args['{{ name }}']} $escaped"
16+
> unique_lookup["{{ name }}:$escaped"]=1
17+
else
18+
> else
19+
> args['{{ name }}']="${args['{{ name }}']} $escaped"
20+
end
21+
22+
else
23+
> args['{{ name }}']="$1"
24+
25+
end

lib/bashly/views/command/parse_requirements_case_catch_all.gtx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
= view_marker
22

33
if args.any?
4-
condition = "if"
5-
args.each do |arg|
6-
> {{ condition }} [[ -z ${args['{{ arg.name }}']+x} ]]; then
7-
> args['{{ arg.name }}']=$1
8-
> shift
9-
10-
condition = "elif"
4+
args.each_with_index do |arg, index|
5+
= arg.render :case, index: index
116
end
127

138
> else

lib/bashly/views/command/parse_requirements_case_repeatable.gtx

Lines changed: 1 addition & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +1,7 @@
11
= view_marker
22

3-
condition = "if"
43
args.each_with_index do |arg, index|
5-
if index == 0
6-
> escaped="$(printf '%q' "$1")"
7-
end
8-
> {{ condition }} [[ -z ${args['{{ arg.name }}']+x} ]]; then
9-
if arg.repeatable
10-
> args['{{ arg.name }}']="$escaped"
11-
if arg.unique
12-
> unique_lookup["{{ arg.name }}:$escaped"]=1
13-
> elif [[ -z "${unique_lookup["{{ arg.name }}:$escaped"]:-}" ]]; then
14-
> args['{{ arg.name }}']="${args['{{ arg.name }}']} $escaped"
15-
> unique_lookup["{{ arg.name }}:$escaped"]=1
16-
else
17-
> else
18-
> args['{{ arg.name }}']="${args['{{ arg.name }}']} $escaped"
19-
end
20-
21-
else
22-
> args['{{ arg.name }}']="$1"
23-
24-
end
25-
condition = "elif"
4+
= arg.render :case_repeatable, index: index
265
end
276

287
> fi

lib/bashly/views/command/parse_requirements_case_simple.gtx

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,8 @@
11
= view_marker
22

33
if args.any?
4-
condition = "if"
5-
args.each do |arg|
6-
> {{ condition }} [[ -z ${args['{{ arg.name }}']+x} ]]; then
7-
> args['{{ arg.name }}']=$1
8-
> shift
9-
10-
condition = "elif"
4+
args.each_with_index do |arg, index|
5+
= arg.render :case, index: index
116
end
127

138
> else

0 commit comments

Comments
 (0)