10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
|
# File 'lib/twee2/decompiler.rb', line 10
def self.decompile(url)
result = ''
html = Nokogiri::HTML(open(url))
raise(DecompilationFailedException, 'tw-storydata not found') unless storydata = html.at_css('tw-storydata')
result << "::StoryTitle\n#{storydata[:name].strip}\n\n"
startnode_pid, startnode_name = storydata[:startnode].strip, nil
if (css = storydata.at_css('#twine-user-stylesheet')) && ((css_content = css.content.strip) != '')
result << "::StoryCSS [stylesheet]\n#{css_content}\n\n"
end
if (js = storydata.at_css('#twine-user-script')) && ((js_content = js.content.strip) != '')
result << "::StoryJS [script]\n#{js.content}\n\n"
end
storydata.css('tw-passagedata').each do |passagedata|
startnode_name = passagedata[:name] if(startnode_pid == passagedata[:pid])
result << "::#{passagedata[:name].strip}"
result << " [#{passagedata[:tags].strip}]" if passagedata[:tags].strip != ''
result << " <#{passagedata[:position].strip}>" if passagedata[:position].strip != ''
result << "\n#{tidyup_passagedata(passagedata.content.strip)}\n\n"
end
result << "::Twee2Settings [twee2]\n"
result << "@story_start_name = '#{startnode_name.gsub("'", "\\'")}'\n" if startnode_name
result << "\n"
result
end
|