middleman / middleman-blog

Blog Engine Extension for Middleman
https://middlemanapp.com
MIT License
326 stars 179 forks source link

How to use lorem helper function inside cli article task #223

Closed ProjectFrank closed 10 years ago

ProjectFrank commented 10 years ago

After setting blog.new_article_template to "article.erb" in config.rb, I am attempting to use

<%= lorem.paragraphs 10 %>

inside my article template. When attempting to generate a new article, there is a backtrace reading:

(erb):6:in `template': undefined local variable or method `lorem' for #<Middleman::Cli::Article:0x0000010341a790> (NameError)
    from /Users/frankwang/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/erb.rb:850:in `eval'
    from /Users/frankwang/.rvm/rubies/ruby-2.1.1/lib/ruby/2.1.0/erb.rb:850:in `result'
    from /Users/frankwang/.rvm/gems/ruby-2.1.1@midleman/gems/thor-0.19.1/lib/thor/actions/file_manipulation.rb:116:in `block in template'
    from /Users/frankwang/.rvm/gems/ruby-2.1.1@midleman/gems/thor-0.19.1/lib/thor/actions/create_file.rb:53:in `call'
    from /Users/frankwang/.rvm/gems/ruby-2.1.1@midleman/gems/thor-0.19.1/lib/thor/actions/create_file.rb:53:in `render'

What is a canonical way of including the helper in this situation?

tdreyno commented 10 years ago

I'm afraid not, the CLI templates can only access the instance variables defined in the command:

          @title
          @slug
          @date
          @lang