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

#write(*a) ⇒ Object



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

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