Skip to content

Commit 8c4583a

Browse files
committed
Refactor 'insert' function to reduce repetition
bump some gems
1 parent 5fbb559 commit 8c4583a

File tree

2 files changed

+24
-19
lines changed

2 files changed

+24
-19
lines changed

Gemfile.lock

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
GEM
22
remote: https://rubygems.org/
33
specs:
4-
activesupport (4.1.6)
4+
activesupport (4.1.7)
55
i18n (~> 0.6, >= 0.6.9)
66
json (~> 1.7, >= 1.7.7)
77
minitest (~> 5.1)
88
thread_safe (~> 0.1)
99
tzinfo (~> 1.1)
10-
bootstrap-sass (3.2.0.2)
10+
bootstrap-sass (3.3.0.1)
1111
sass (~> 3.2)
1212
celluloid (0.16.0)
1313
timers (~> 4.0.0)
@@ -29,7 +29,7 @@ GEM
2929
eventmachine (1.0.3)
3030
ffi (1.9.6)
3131
files (0.3.1)
32-
font-awesome-sass (4.2.1)
32+
font-awesome-sass (4.2.2)
3333
sass (~> 3.2)
3434
hike (1.2.3)
3535
hitimes (1.2.2)
@@ -41,11 +41,11 @@ GEM
4141
celluloid (>= 0.15.2)
4242
rb-fsevent (>= 0.9.3)
4343
rb-inotify (>= 0.9)
44-
mini_portile (0.6.0)
44+
mini_portile (0.6.1)
4545
minitest (5.4.2)
4646
multi_json (1.10.1)
47-
nokogiri (1.6.3.1)
48-
mini_portile (= 0.6.0)
47+
nokogiri (1.6.4.1)
48+
mini_portile (~> 0.6.0)
4949
polyglot (0.3.5)
5050
predicated (0.2.6)
5151
rack (1.5.2)
@@ -80,13 +80,13 @@ GEM
8080
sexp_processor (~> 4.0)
8181
ruby_parser (3.6.3)
8282
sexp_processor (~> 4.1)
83-
sass (3.4.6)
83+
sass (3.4.7)
8484
sexp_processor (4.4.4)
8585
sinatra (1.4.5)
8686
rack (~> 1.4)
8787
rack-protection (~> 1.4)
8888
tilt (~> 1.3, >= 1.3.4)
89-
sprockets (2.12.2)
89+
sprockets (2.12.3)
9090
hike (~> 1.2)
9191
multi_json (~> 1.0)
9292
rack (~> 1.0)

lib/step.rb

+16-11
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,23 @@ def insert file
4444

4545
# todo: other file types
4646

47-
if File.exist?(path = File.join(dir, "_#{file}.step"))
48-
src = File.read(path)
49-
step = Step.new(src: src, doc_path: path, container_page_name: page_name, step_stack: @step_stack)
50-
widget step
51-
elsif File.exist?(path = File.join(dir, "#{file}.step"))
52-
src = File.read(path)
53-
step = Step.new(src: src, doc_path: path, container_page_name: page_name, step_stack: @step_stack)
54-
widget step
55-
elsif File.exist?(path = File.join(dir, "#{file}.md"))
56-
src = File.read(path)
57-
message src
47+
possible_paths = ["_#{file}.step", "#{file}.step", "#{file}.md"].map do |path|
48+
File.join(dir, path)
5849
end
50+
51+
possible_paths.each do |path|
52+
if File.exist?(path)
53+
src = File.read(path)
54+
if path.end_with?('.step')
55+
step = Step.new(src: src, doc_path: path, container_page_name: page_name, step_stack: @step_stack)
56+
return widget step
57+
else
58+
return message src
59+
end
60+
end
61+
end
62+
63+
raise "Couldn't find a partial for #{file}!"
5964
end
6065

6166
## steps

0 commit comments

Comments
 (0)