An Easy Way to Setup the gon gem in a Discourse Plugin

Version 0.1.4

Update:

This version eliminate the need to modify the Discourse container file.

The plugin will not do the required layout changes (inject gon), as follows:

class GonLayoutChanges
  def self.add_gon_to_head
    head_file = "#{Rails.root}/app/views/layouts/_head.html.erb"
    if File.readlines(head_file).grep(/include_gon/).size < 1
      tmp_file = "/shared/tmp/work.tmp.txt"
      gon_text = "<%= include_gon if defined? gon && gon.present? %>\n"
      IO.write(tmp_file, gon_text)
      IO.foreach(head_file) do |line|
        IO.write(tmp_file, line, mode: "a")
      end
      FileUtils.mv(tmp_file, head_file)
    end
  end
end