I wanted the following:
source/blog/2013-05-29-middleman.html.markdown.erb
source/blog/2013-05-29-middleman/middleman.svg
rendered to:
build/blog/2013/05/29/middleman/index.html
build/blog/2013/05/29/middleman/index.html.gz
build/blog/2013/05/29/middleman/middleman.svg
I succeeded doing so with a little help of a helper Image:
module Image
class << self
def registered(app)
app.helpers Helpers
end
alias :included :registered
end
module Helpers
def image(file, options={})
title = current_article.title
"/blog/#{title}/#{file}"
end
end
end
::Middleman::Extensions.register(:image, Image)
and calling the helper in markdown in my blog article.
The blog article itself rendered fine, but it’s summary used in an collection of articles in index.html.erb not:
---
title: 4pdj
per_page: 10
---
<% blog.articles[0...10].each do |article| %>
<article>
<h1><a href="<%= article.url %>"><%= article.title %></a></h1>
<%= article.summary %>
<a href="<%= article.url %>" class="btn disabled"><i class="icon-zoom-in"></i> read more</a>
</article>
<% end %>
current_article is not nil but the method current_article.title is unknown:
error build/index.html
undefined method `title' for nil:NilClass
/var/www/4pdj.nl/blog/lib/image.rb:11:in `image'
/var/www/4pdj.nl/blog/source/blog/2013-05-29-middleman.html.markdown.erb:1:in `block in singletonclass'
/var/www/4pdj.nl/blog/source/blog/2013-05-29-middleman.html.markdown.erb:65530:in `instance_eval'
/var/www/4pdj.nl/blog/source/blog/2013-05-29-middleman.html.markdown.erb:65530:in `singletonclass'
/var/www/4pdj.nl/blog/source/blog/2013-05-29-middleman.html.markdown.erb:65528:in `__tilt_17193080'
/var/lib/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:144:in `call'
/var/lib/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:144:in `evaluate'
/var/lib/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/rendering.rb:264:in `render_individual_file'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/rendering.rb:148:in `render_template'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/resource.rb:128:in `block in render'
/var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:125:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/util.rb:60:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/application.rb:222:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/resource.rb:14:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/resource.rb:114:in `render'
/var/lib/gems/1.9.1/gems/middleman-blog-3.2.0/lib/middleman-blog/blog_article.rb:19:in `render'
/var/lib/gems/1.9.1/gems/middleman-blog-3.2.0/lib/middleman-blog/blog_article.rb:72:in `summary'
/var/www/4pdj.nl/blog/source/index.html.erb:4:in `block (2 levels) in singletonclass'
/var/www/4pdj.nl/blog/source/index.html.erb:1:in `each'
/var/www/4pdj.nl/blog/source/index.html.erb:1:in `block in singletonclass'
/var/www/4pdj.nl/blog/source/index.html.erb:65530:in `instance_eval'
/var/www/4pdj.nl/blog/source/index.html.erb:65530:in `singletonclass'
/var/www/4pdj.nl/blog/source/index.html.erb:65528:in `__tilt_17193080'
/var/lib/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:144:in `call'
/var/lib/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:144:in `evaluate'
/var/lib/gems/1.9.1/gems/tilt-1.3.7/lib/tilt/template.rb:77:in `render'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/rendering.rb:264:in `render_individual_file'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/rendering.rb:148:in `render_template'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/resource.rb:128:in `block in render'
/var/lib/gems/1.9.1/gems/activesupport-3.2.13/lib/active_support/notifications.rb:125:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/util.rb:60:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/application.rb:222:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/resource.rb:14:in `instrument'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/sitemap/resource.rb:114:in `render'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/request.rb:255:in `process_request'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/request.rb:204:in `block in call!'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/request.rb:203:in `catch'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/request.rb:203:in `call!'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/core_extensions/request.rb:188:in `call'
/var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:134:in `call'
/var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:64:in `block in call'
/var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in `each'
/var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/urlmap.rb:49:in `call'
/var/lib/gems/1.9.1/gems/htmlcompressor-0.0.6/lib/htmlcompressor/rack.rb:36:in `call'
/var/lib/gems/1.9.1/gems/middleman-more-3.0.14/lib/middleman-more/extensions/minify_javascript.rb:51:in `call'
/var/lib/gems/1.9.1/gems/middleman-more-3.0.14/lib/middleman-more/extensions/minify_css.rb:50:in `call'
/var/lib/gems/1.9.1/gems/rack-1.4.5/lib/rack/builder.rb:134:in `call'
/var/lib/gems/1.9.1/gems/rack-test-0.6.2/lib/rack/mock_session.rb:30:in `request'
/var/lib/gems/1.9.1/gems/rack-test-0.6.2/lib/rack/test.rb:230:in `process_request'
/var/lib/gems/1.9.1/gems/rack-test-0.6.2/lib/rack/test.rb:57:in `get'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli/build.rb:137:in `render_to_file'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli/build.rb:282:in `block in execute!'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli/build.rb:279:in `each'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli/build.rb:279:in `execute!'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli/build.rb:198:in `invoke!'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/actions.rb:95:in `action'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli/build.rb:65:in `build'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/task.rb:27:in `run'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli.rb:77:in `method_missing'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/task.rb:29:in `run'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/task.rb:126:in `run'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/invocation.rb:120:in `invoke_task'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor.rb:275:in `dispatch'
/var/lib/gems/1.9.1/gems/thor-0.15.4/lib/thor/base.rb:425:in `start'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/lib/middleman-core/cli.rb:22:in `start'
/var/lib/gems/1.9.1/gems/middleman-core-3.0.14/bin/middleman:18:in `<top (required)>'
/usr/local/bin/middleman:19:in `load'
/usr/local/bin/middleman:19:in `<main>'
How do I correctly reference frontmatter title so both the article summary and article will render correctly?