mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
sanctuary: simplify filter
This commit is contained in:
parent
a63f32ca76
commit
0536298501
2 changed files with 9 additions and 25 deletions
|
@ -1,11 +1,3 @@
|
|||
def repeat(n, s)
|
||||
Array.new(n, s).join("")
|
||||
end
|
||||
|
||||
def _(n)
|
||||
repeat(n, " ")
|
||||
end
|
||||
|
||||
module Docs
|
||||
|
||||
class Sanctuary
|
||||
|
@ -44,23 +36,7 @@ module Docs
|
|||
node
|
||||
.css("input")
|
||||
.map { |node| "> " + node.attributes["value"].value }
|
||||
.zip(node.css(".output").map { |node|
|
||||
if node.content.start_with?("! Invalid value")
|
||||
# XXX: Reinstate newlines and consecutive spaces.
|
||||
content = node.content.dup()
|
||||
content[ 15] = "\n\n"
|
||||
content[ 68] = "\n" + _("add :: FiniteNumber -> ".size)
|
||||
content[104] = "\n" + _("add :: FiniteNumber -> ".size + ("FiniteNumber".size - 1) / 2)
|
||||
content[134] = "\n\n"
|
||||
content[138] = _(2)
|
||||
content[155] = "\n\n"
|
||||
content[215] = "\n\n"
|
||||
content[337] = "\n"
|
||||
content
|
||||
else
|
||||
node.content
|
||||
end
|
||||
})
|
||||
.zip(node.css(".output").map { |node| node.content })
|
||||
.map { |pair| pair.join("\n") }
|
||||
.join("\n\n"),
|
||||
{"data-language" => "javascript"}
|
||||
|
|
|
@ -20,6 +20,14 @@ module Docs
|
|||
def get_latest_version(opts)
|
||||
get_npm_version("sanctuary", opts)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def parse(response) # Hook here because Nokogori removes whitespace from textareas
|
||||
response.body.gsub! %r{<div class="output"[^>]*>([\W\w]+?)</div>}, '<pre class="output">\1</pre>'
|
||||
super
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue