<commit_before>require 'jrubyfx'
fxml_root File.dirname(__FILE__)

class ReviewEditorApp < JRubyFX::Application
  def start(stage)

    with(stage, title: "Re:VIEW Editor", width: 600, height: 600) do
      fxml ReviewEditorController
      show
    end
  end
end

class ReviewEditorController
  include JRubyFX::Controller
  fxml "review-editor.fxml"

  def compile
    compiled = ReviewEditor.new.compile(@input.getText)
    @output.getEngine.loadContent(compiled)
  end
end

$LOAD_PATH << "review/lib"
require 'review'
class ReviewEditor
  include ReVIEW

  def initialize
    @builder = HTMLBuilder.new
    @book = Book::Base.new(".")
    @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
    @compiler = Compiler.new(@builder)
    @builder.bind(@compiler, @chapter, Location.new(nil, nil))
    I18n.setup("ja")
  end

  def compile(text)
    "" if text.empty?

    @chapter.content = text
    matched = @compiler.compile(@chapter).match(/<body>\n(.+)<\/body>/m)
    if matched && matched.size > 1
      matched[1]
    else
      ""
    end
  rescue
    ""
  end
end

ReviewEditorApp.launch<commit_msg>Re-use instance of ReviewEditor<commit_after>require 'jrubyfx'
fxml_root File.dirname(__FILE__)

class ReviewEditorApp < JRubyFX::Application
  def start(stage)

    with(stage, title: "Re:VIEW Editor", width: 600, height: 600) do
      fxml ReviewEditorController
      show
    end
  end
end

class ReviewEditorController
  include JRubyFX::Controller
  fxml "review-editor.fxml"

  def compile
    compiled = $review_editor.compile(@input.getText)
    @output.getEngine.loadContent(compiled)
  end
end

$LOAD_PATH << "review/lib"
require 'review'
class ReviewEditor
  include ReVIEW

  def initialize
    @builder = HTMLBuilder.new
    @book = Book::Base.new(".")
    @chapter = Book::Chapter.new(@book, 1, '-', nil, StringIO.new)
    @compiler = Compiler.new(@builder)
    @builder.bind(@compiler, @chapter, Location.new(nil, nil))
    I18n.setup("ja")
  end

  def compile(text)
    "" if text.empty?

    @chapter.content = text
    matched = @compiler.compile(@chapter).match(/<body>\n(.+)<\/body>/m)
    if matched && matched.size > 1
      matched[1]
    else
      ""
    end
  rescue
    ""
  end
end

$review_editor = ReviewEditor.new

ReviewEditorApp.launch
{'fraction_non_alphanumeric': 0.12756662297946703, 'fraction_numerical': 0.009611183923110528, 'mean_word_length': 3.4466019417475726, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 8}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3660963', 'n_tokens_mistral': 792, 'n_tokens_neox': 737, 'n_words': 170}