Module: Twee2
- Defined in:
- lib/twee2.rb,
lib/twee2/version.rb,
lib/twee2/decompiler.rb,
lib/twee2/story_file.rb,
lib/twee2/build_config.rb,
lib/twee2/story_format.rb
Defined Under Namespace
Classes: BuildConfig, DecompilationFailedException, Decompiler, StoryFile, StoryFileNotFoundException, StoryFormat, StoryFormatNotFoundException
Constant Summary
collapse
- DEFAULT_FORMAT =
'Harlowe'
- VERSION =
"0.4.1"
Class Method Summary
collapse
Class Method Details
.build(input, output, options = {}) ⇒ Object
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.rb', line 14
def self.build(input, output, options = {})
begin
build_config.story_file = StoryFile::new(input)
rescue StoryFileNotFoundException
puts "ERROR: story file '#{input}' not found."
exit
end
if !build_config.story_format
begin
build_config.story_format = StoryFormat::new(options[:format])
rescue StoryFormatNotFoundException
puts "ERROR: story format '#{options[:format]}' not found."
exit
end
end
if !build_config.story_ifid_specified
puts "NOTICE: You haven't specified your IFID. Consider adding to your code -"
puts "::StoryIFID[twee2]\nTwee2::build_config.story_ifid = '#{build_config.story_ifid}'"
end
File::open(output, 'w') do |out|
out.print build_config.story_format.compile
end
puts "Done"
end
|
.build_config ⇒ Object
25
26
27
|
# File 'lib/twee2/build_config.rb', line 25
def self.build_config
BuildConfig::instance
end
|
.buildpath(path) ⇒ Object
82
83
84
|
# File 'lib/twee2.rb', line 82
def self.buildpath(path)
File.join(File.dirname(File.expand_path(__FILE__)), "../#{path}")
end
|
.decompile(url, output) ⇒ Object
Reverse-engineers a Twee2/Twine 2 output HTML file into a Twee2 source file
69
70
71
72
73
74
|
# File 'lib/twee2.rb', line 69
def self.decompile(url, output)
File::open(output, 'w') do |out|
out.print Decompiler::decompile(url)
end
puts "Done"
end
|
53
54
55
56
|
# File 'lib/twee2.rb', line 53
def self.formats
puts "I understand the following output formats:"
puts StoryFormat.known_names.join("\n")
end
|
.help ⇒ Object
77
78
79
80
|
# File 'lib/twee2.rb', line 77
def self.help
puts "Twee2 #{Twee2::VERSION}"
puts File.read(buildpath('doc/usage.txt'))
end
|
.version_check ⇒ Object
58
59
60
61
62
63
64
65
|
# File 'lib/twee2.rb', line 58
def self.version_check
`gem list -r -q twee2` =~ /\((.*)\)/
puts " Your version: #{Twee2::VERSION}"
puts " Latest version: #{$1}"
if Twee2::VERSION.to_s != $1
puts "To upgrade, run: gem install twee2"
end
end
|
.watch(input, output, options = {}) ⇒ Object
43
44
45
46
47
48
49
50
51
|
# File 'lib/twee2.rb', line 43
def self.watch(input, output, options = {})
puts "Compiling #{output}"
build(input, output, options)
puts "Watching #{input}"
FileWatcher.new(input).watch do
puts "Recompiling #{output}"
build(input, output, options)
end
end
|