yjpark / jekyll-plantuml

Jekyll / Octopress plugin to generate PlantUML diagrams
Other
33 stars 3 forks source link

The plugin is called 3 times for each block #9

Closed aleung closed 9 years ago

aleung commented 10 years ago

For each plantuml block, there are two png files generated, one is correct and the another is showing a 'Syntax error' message from plantuml. But browsing the generated site, no matter index page or single blog page, the graph is correct. The incorrect png file isn't referenced in any page.

To trace the cause, I put two lines into plantuml.rb to print debug information:

  puts "Code: " + code + "\n"
  puts caller.join("\n")

First time:

Code:  
package ConsentObject <<Rect>> {
  Consent : id
  Scope : key
}

Client - User
(Client, User) . Consent

Consent - "*" Scope

Consent "1" -- "1..*" AccessToken

/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:94:in `block in render_all'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `collect'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `render_all'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:82:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/template.rb:124:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/template.rb:132:in `render!'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/convertible.rb:79:in `do_layout'
/Users/leoliang/Projects/octopress/plugins/post_filters.rb:167:in `do_layout'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/post.rb:195:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:200:in `block in render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:199:in `each'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:199:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:41:in `process'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/bin/jekyll:253:in `block in <top (required)>'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:580:in `call'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:580:in `block in notify_observers'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:579:in `each'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:579:in `notify_observers'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:334:in `block in initialize'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:224:in `call'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:224:in `notify'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:102:in `run_once'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:150:in `run_loop'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:45:in `block in start'

Second time:

Code:  
package ConsentObject «Rect» {
  Consent : id
  Scope : key
}</p>

<p>Client - User
(Client, User) . Consent</p>

<p>Consent - “*” Scope</p>

<p>Consent “1” – “1..*” AccessToken

/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:94:in `block in render_all'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `collect'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:92:in `render_all'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/block.rb:82:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/template.rb:124:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/liquid-2.3.0/lib/liquid/template.rb:132:in `render!'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/convertible.rb:79:in `do_layout'
/Users/leoliang/Projects/octopress/plugins/post_filters.rb:167:in `do_layout'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/page.rb:100:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:204:in `block in render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:203:in `each'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:203:in `render'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/lib/jekyll/site.rb:41:in `process'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/jekyll-0.12.0/bin/jekyll:253:in `block in <top (required)>'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:580:in `call'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:580:in `block in notify_observers'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:579:in `each'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:579:in `notify_observers'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher.rb:334:in `block in initialize'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:224:in `call'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:224:in `notify'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:102:in `run_once'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:150:in `run_loop'
/Users/leoliang/.rvm/gems/ruby-1.9.3-p327/gems/directory_watcher-1.4.1/lib/directory_watcher/scanner.rb:45:in `block in start'

The code passed in has been rendered into HTML, so plantuml reported syntax error.

The third time is same as the second time. Because the code is same as the second time, there is no graph generated.

Following the stack trace, I found the different is in jekyll-0.12.0/lib/jekyll/site.rb.

def render
  payload = site_payload
  self.posts.each do |post|
    post.render(self.layouts, payload)
  end

  self.pages.each do |page|
    page.render(self.layouts, payload)
  end

  self.categories.values.map { |ps| ps.sort! { |a, b| b <=> a } }
  self.tags.values.map { |ps| ps.sort! { |a, b| b <=> a } }
rescue Errno::ENOENT => e
  # ignore missing layout dir
end

The first call (normal one) is from post.render() and the second and third calls (wrong) are from page.render().

I don't think it is the fault of this plugin. But I just know very little Ruby and don't know Jekyll, so I have no more idea. Record it here to check if anybody meets the same issue.

yjpark commented 10 years ago

Thanks a lot for using this plugin and paste your findings here.

I noticed that it's called multiple times, though my ruby skill is so little, my solution was to check whether the png file already been created.