twee2 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ab84ccf632ecb0d8406411affe8c510bdf21cd9
4
- data.tar.gz: e29c5f719f01c0091ca58a4b1cef9c9bd1da265c
3
+ metadata.gz: 56b36c1e681bbb26c4908a3418e887ea9dedcdc5
4
+ data.tar.gz: 8abeebae4c760910de847591918f14a567759699
5
5
  SHA512:
6
- metadata.gz: 06fb4004be941570eded9e5362a384f3aa8efbf290238c91417733203d4951aea9514fe441cbd625d9696e2eb503a44e55022b8695ccf656479c63e3a05cbab8
7
- data.tar.gz: 4e5f2fbffb9570f3688553370a69694d87ad7c8b5bc4906c770f93f4258700b79ebb15d05fbda138b1dc4347efce291e88f4ba33f1c279c47845b25e18257e4c
6
+ metadata.gz: b8d4a3dfdc52ffbec9bbe209e944549999927e199d8bbf83ab40a27f65c726d0d2a354acec0ddd508dbfbeae2d21d4dc03321bfcd6d023393a2afc682fb86600
7
+ data.tar.gz: 003ab07e54edff64f7799ce3c33d0a093c146062c7b5e887305f222530d9782c9c1b4ce9aa898fa7046e80117d86e728e631ad34bc1677441d76d7f8a454c529
@@ -16,6 +16,7 @@ Usage:
16
16
  twee2 decompile [URL] [output.tw2]
17
17
  Decompiles a Twee2/Twine 2 HTML output file at a specified URL into
18
18
  a Twee2 source file.
19
+ NOT AVAILABLE ON MICROSOFT WINDOWS.
19
20
 
20
21
  twee2 help
21
22
  Displays this message.
@@ -38,12 +38,14 @@ module Twee2
38
38
  puts StoryFormat.known_names.join("\n")
39
39
  end
40
40
 
41
- # Reverse-engineers a Twee2/Twine 2 output HTML file into a Twee2 source file
42
- def self.decompile(url, output)
43
- File::open(output, 'w') do |out|
44
- out.print Decompiler::decompile(url)
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
@@ -1,51 +1,54 @@
1
- require 'open-uri'
2
- require 'nokogiri'
1
+ unless Gem.win_platform?
2
+ require 'rubygems'
3
+ require 'open-uri'
4
+ require 'nokogiri'
3
5
 
4
- module Twee2
5
- class DecompilationFailedException < Exception; end
6
+ module Twee2
7
+ class DecompilationFailedException < Exception; end
6
8
 
7
- class Decompiler
8
- def self.decompile(url)
9
- result = ''
10
- # Load the compiled HTML and sanity-check it
11
- html = Nokogiri::HTML(open(url))
12
- raise(DecompilationFailedException, 'tw-storydata not found') unless storydata = html.at_css('tw-storydata')
13
- # Extract the tw-storydata#name (StoryTitle) and #startnode
14
- result << "::StoryTitle\n#{storydata[:name].strip}\n\n"
15
- startnode_pid, startnode_name = storydata[:startnode].strip, nil
16
- # Extract the custom CSS and Javascript, if applicable
17
- if (css = storydata.at_css('#twine-user-stylesheet')) && ((css_content = css.content.strip) != '')
18
- result << "::StoryCSS [stylesheet]\n#{css_content}\n\n"
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
- protected
43
+ protected
42
44
 
43
- # Fixes common problems with decompiled passage content
44
- def self.tidyup_passagedata(passagedata_content)
45
- passagedata_content.gsub(/\[\[ *(.*?) *\]\]/, '[[\1]]'). # remove excess spacing within links: not suitable for Twee-style source
46
- gsub(/\[\[ *(.*?) *<- *(.*?) *\]\]/, '[[\1<-\2]]'). # ditto
47
- gsub(/\[\[ *(.*?) *-> *(.*?) *\]\]/, '[[\1->\2]]'). # ditto
48
- gsub(/\[\[ *(.*?) *\| *(.*?) *\]\]/, '[[\1|\2]]') # ditto
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
@@ -1,3 +1,3 @@
1
1
  module Twee2
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: twee2
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan Q