123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 |
- task default: %w(develop)
- STORY_DIR=File.join(ENV['USERPROFILE'], 'Documents\\Twine\\Stories')
- STORY_TITLE = 'Volleyball'
- FILES = {
- 'intro' => 'Intro',
- 'transform' => 'Transform',
- 'custom_girl' => 'Custom Girl',
- 'beaches' => 'Beaches',
- 'money_game' => 'Money Games',
- }
- def files
- FILES.map do |short_name, long_name|
- OpenStruct.new({
- short_name: short_name,
- long_name: long_name,
- source_file: "#{short_name}.tw2",
- dest_file: File.join(STORY_DIR, "#{STORY_TITLE} - #{long_name}.html"),
- wrapper_file: "#{short_name}_wrapper.tw2",
- })
- end
- end
- task develop: %w(bundle_install) do
- sh "bundle exec twee2 build main.tw2 develop.html"
- end
- task watch: %w(bundle_install) do
- sh 'start watch.html' # FIXME non-windows
- sh "bundle exec twee2 watch main.tw2 watch.html"
- end
- task release: %w(bundle_install) do
- sh "bundle exec twee2 build main.tw2 release.html"
- end
- desc 'export sub files to Twine 2'
- task export: %w(bundle_install) do
- files.each do |file|
- IO.write file.wrapper_file, <<~EOF
- ::StoryTitle
- Volleyball - #{file.long_name}
- ::Twee2Settings [twee2]
- @story_start_name = 'Start #{file.long_name}'
- Twee2::build_config.story_format = 'SugarCube2'
- ::StoryIncludes
- images.tw2
- stylesheet.tw2
- storyjs.tw2
- #{file.source_file}
- EOF
- sh 'bundle', 'exec', 'twee2', 'export', file.wrapper_file, file.dest_file
- end
- sh 'bundle', 'exec', 'twee2', 'export', 'main.tw2', STORY_DIR
- end
- desc 'import sub files from Twine 2'
- task import: %w(bundle_install) do
- files.each do |file|
- sh(
- 'bundle', 'exec', 'twee2', 'decompile',
- file.dest_file, file.source_file,
- '--exclude=StoryJS,StoryCSS,StoryTitle,Twee2Settings',
- '--exclude-from=storyjs.tw2,stylesheet.tw2,images.tw2"',
- )
- end
- end
- task :bundle_install do
- sh 'bundle install'
- end
- task :clean do
- # TODO
- end
- task :lint do
- FILES.each do |short_name, long_name|
- filename = "#{short_name}.tw2"
- twee_source = IO.read(filename)
- twee_source.lines.each_with_index do |line, lineno|
- lineno += 1
- line
- .scan(%r{\[\[([^\]]*)\]\]})
- .map { |x| x[0] }
- .each do |link|
- case link.scan('->').length
- when 0
- #puts("link contains no ->, probably not a problem")
- next
- when 1
- # no problem
- else
- puts("link contains multiple -> definitely a problem")
- next
- end
- text, dest = link.split('->')
- if text.start_with?('\'')
- if !text.end_with?('\'')
- puts("#{filename}:#{lineno} link text (#{text.inspect}) does not end with single quote despite starting with one")
- next
- end
- text = text[1..-2]
- text
- .to_enum(:scan, '\'')
- .map {Regexp.last_match.offset(0)[0]}
- .each do |offset|
- if text[offset - 1] != '\\'
- puts "#{filename}:#{lineno} link text (#{text.inspect}) contains unquoted single quote in body"
- end
- end
- elsif text.start_with?('"')
- if !text.end_with?('"')
- puts("#{filename}:#{lineno} link text (#{text.inspect}) does not end with double quote despite starting with one")
- next
- end
- text = text[1..-2]
- text
- .to_enum(:scan, '"')
- .map {Regexp.last_match.offset(0)[0]}
- .each do |offset|
- if text[offset - 1] != '\\'
- puts "#{filename}:#{lineno} link text (#{text.inspect}) contains unquoted double quote in body"
- end
- end
- elsif text =~ /\A[\[\]'"\\]*\Z/
- puts "#{filename}:#{lineno} link text (#{text.inspect}) contains special characters but is not quoted with single or double quotes"
- end
- #puts(dest)
- end
- end
- end
- end
|