Class: NanDoc::CreateNanDocSite::SupremeStderrHack

Inherits:
Object
  • Object
show all
Defined in:
lib/nandoc/commands/create-nandoc-site.rb

Instance Method Summary collapse

Constructor Details

#initialize(real) ⇒ SupremeStderrHack

ridiculous: make a state machine that rewrites part of the error message coming from nanoc, then gets rid of itself when it’s done. This is so fragile and stupid but I really needed to get the nanoc message (“please file bug reports”) out of the error message so ppl don’t misfile bug reports there that are actually NanDoc bugs.



188
189
190
191
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 188

def initialize real
  @ui = real
  @state = :looking_for_error_header
end

Instance Method Details

#puts(*a) ⇒ Object



192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 192

def puts *a
  case @state
  when :looking_for_error_header
    if a.first && a.first.include?('/!\ ERROR /!\\')
      @state = :waiting_for_end_of_error_box
      @ui.puts "     +--- /!\\ ERROR /!\\ --------------------------------------------+\n     | An exception occured while running nandoc. If you think this |\n     | is a bug in nandoc (likely), please report it at             |\n     | <http://github.com/hipe/nandoc/issues> -- thanks!            |\n     | (it is very likely a treebis patch failure)                  |\n     +--------------------------------------------------------------+\n     HERE\n    else\n      @ui.puts(*a) # probably just whitespace?\n    end\n  when :waiting_for_end_of_error_box\n    if a.first && a.first =~ /\\+-+\\+/\n      $stderr = @ui\n      @state = :hack_failed\n        # nothing should be callig our puts() method any more\n    end\n  when :hack_failed\n    fail(\"hack failed\")\n  else\n    fail(\"huh?\")\n  end\nend\n".gsub(/^ +/,'')

#write(*a) ⇒ Object



220
221
222
# File 'lib/nandoc/commands/create-nandoc-site.rb', line 220

def write *a
  @ui.write(*a)
end