twee2 0.3.2 → 0.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/doc/usage.txt +1 -0
- data/lib/twee2.rb +7 -5
- data/lib/twee2/decompiler.rb +46 -43
- data/lib/twee2/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56b36c1e681bbb26c4908a3418e887ea9dedcdc5
|
4
|
+
data.tar.gz: 8abeebae4c760910de847591918f14a567759699
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b8d4a3dfdc52ffbec9bbe209e944549999927e199d8bbf83ab40a27f65c726d0d2a354acec0ddd508dbfbeae2d21d4dc03321bfcd6d023393a2afc682fb86600
|
7
|
+
data.tar.gz: 003ab07e54edff64f7799ce3c33d0a093c146062c7b5e887305f222530d9782c9c1b4ce9aa898fa7046e80117d86e728e631ad34bc1677441d76d7f8a454c529
|
data/doc/usage.txt
CHANGED
data/lib/twee2.rb
CHANGED
@@ -38,12 +38,14 @@ module Twee2
|
|
38
38
|
puts StoryFormat.known_names.join("\n")
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
41
|
+
unless Gem.win_platform?
|
42
|
+
# Reverse-engineers a Twee2/Twine 2 output HTML file into a Twee2 source file
|
43
|
+
def self.decompile(url, output)
|
44
|
+
File::open(output, 'w') do |out|
|
45
|
+
out.print Decompiler::decompile(url)
|
46
|
+
end
|
47
|
+
puts "Done"
|
45
48
|
end
|
46
|
-
puts "Done"
|
47
49
|
end
|
48
50
|
|
49
51
|
def self.help
|
data/lib/twee2/decompiler.rb
CHANGED
@@ -1,51 +1,54 @@
|
|
1
|
-
|
2
|
-
require '
|
1
|
+
unless Gem.win_platform?
|
2
|
+
require 'rubygems'
|
3
|
+
require 'open-uri'
|
4
|
+
require 'nokogiri'
|
3
5
|
|
4
|
-
module Twee2
|
5
|
-
|
6
|
+
module Twee2
|
7
|
+
class DecompilationFailedException < Exception; end
|
6
8
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
9
|
+
class Decompiler
|
10
|
+
def self.decompile(url)
|
11
|
+
result = ''
|
12
|
+
# Load the compiled HTML and sanity-check it
|
13
|
+
html = Nokogiri::HTML(open(url))
|
14
|
+
raise(DecompilationFailedException, 'tw-storydata not found') unless storydata = html.at_css('tw-storydata')
|
15
|
+
# Extract the tw-storydata#name (StoryTitle) and #startnode
|
16
|
+
result << "::StoryTitle\n#{storydata[:name].strip}\n\n"
|
17
|
+
startnode_pid, startnode_name = storydata[:startnode].strip, nil
|
18
|
+
# Extract the custom CSS and Javascript, if applicable
|
19
|
+
if (css = storydata.at_css('#twine-user-stylesheet')) && ((css_content = css.content.strip) != '')
|
20
|
+
result << "::StoryCSS [stylesheet]\n#{css_content}\n\n"
|
21
|
+
end
|
22
|
+
if (js = storydata.at_css('#twine-user-script')) && ((js_content = js.content.strip) != '')
|
23
|
+
result << "::StoryJS [script]\n#{js.content}\n\n"
|
24
|
+
end
|
25
|
+
# Extract each passage
|
26
|
+
storydata.css('tw-passagedata').each do |passagedata|
|
27
|
+
# Check if this is the start passage and record this accordingly
|
28
|
+
startnode_name = passagedata[:name] if(startnode_pid == passagedata[:pid])
|
29
|
+
# Write the passage out
|
30
|
+
result << "::#{passagedata[:name].strip}"
|
31
|
+
result << " [#{passagedata[:tags].strip}]" if passagedata[:tags].strip != ''
|
32
|
+
result << " <#{passagedata[:position].strip}>" if passagedata[:position].strip != ''
|
33
|
+
result << "\n#{tidyup_passagedata(passagedata.content.strip)}\n\n"
|
34
|
+
end
|
35
|
+
# Write the Twee2 settings out (compatability layer)
|
36
|
+
result << "::Twee2Settings [twee2]\n"
|
37
|
+
result << "@story_start_name = '#{startnode_name.gsub("'", "\\'")}'\n" if startnode_name
|
38
|
+
result << "\n"
|
39
|
+
# Return the result
|
40
|
+
result
|
19
41
|
end
|
20
|
-
if (js = storydata.at_css('#twine-user-script')) && ((js_content = js.content.strip) != '')
|
21
|
-
result << "::StoryJS [script]\n#{js.content}\n\n"
|
22
|
-
end
|
23
|
-
# Extract each passage
|
24
|
-
storydata.css('tw-passagedata').each do |passagedata|
|
25
|
-
# Check if this is the start passage and record this accordingly
|
26
|
-
startnode_name = passagedata[:name] if(startnode_pid == passagedata[:pid])
|
27
|
-
# Write the passage out
|
28
|
-
result << "::#{passagedata[:name].strip}"
|
29
|
-
result << " [#{passagedata[:tags].strip}]" if passagedata[:tags].strip != ''
|
30
|
-
result << " <#{passagedata[:position].strip}>" if passagedata[:position].strip != ''
|
31
|
-
result << "\n#{tidyup_passagedata(passagedata.content.strip)}\n\n"
|
32
|
-
end
|
33
|
-
# Write the Twee2 settings out (compatability layer)
|
34
|
-
result << "::Twee2Settings [twee2]\n"
|
35
|
-
result << "@story_start_name = '#{startnode_name.gsub("'", "\\'")}'\n" if startnode_name
|
36
|
-
result << "\n"
|
37
|
-
# Return the result
|
38
|
-
result
|
39
|
-
end
|
40
42
|
|
41
|
-
|
43
|
+
protected
|
42
44
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
45
|
+
# Fixes common problems with decompiled passage content
|
46
|
+
def self.tidyup_passagedata(passagedata_content)
|
47
|
+
passagedata_content.gsub(/\[\[ *(.*?) *\]\]/, '[[\1]]'). # remove excess spacing within links: not suitable for Twee-style source
|
48
|
+
gsub(/\[\[ *(.*?) *<- *(.*?) *\]\]/, '[[\1<-\2]]'). # ditto
|
49
|
+
gsub(/\[\[ *(.*?) *-> *(.*?) *\]\]/, '[[\1->\2]]'). # ditto
|
50
|
+
gsub(/\[\[ *(.*?) *\| *(.*?) *\]\]/, '[[\1|\2]]') # ditto
|
51
|
+
end
|
49
52
|
end
|
50
53
|
end
|
51
54
|
end
|
data/lib/twee2/version.rb
CHANGED