middleman console: how to use it?

只愿长相守 提交于 2019-12-13 11:40:29

问题


I would like to know how to use middleman console. Is it a simple irb? What can I do with it that differs from the simple irb?

middleman console [options]         # Start an interactive console in the cont...

I have some articles and I try to do Article.all but I had this following error:

NameError: uninitialized constant Middleman::Application::MiddlemanApplication1::Article
    from (irb#1):1

and I also have local-data /data/friends.json but Friend.all output error too.

{
  "friends": [
    "Tom",
    "Dick",
    "Harry"
  ]
}

I saw that Symbol.all_symbols output a lots of middleman variable and functions but I don't really know how to use the middleman console.


回答1:


Oh man, I just spend a few hours trying to solve something that would have gone a lot faster if I had known that there was a middleman console!

I was trying to build the next/back logic for going through articles on my blog. There's a chronological thing, but I wanted to also be able to go back and forth on tags. There are a few that are tagged both "ruby" and (say) "rails", and "the next" for both tags was the same I wanted to list it together under both the tags.

The main problem was that I didn't know what sorts of things were available to me in the templates file. When you startup middleman console it loads up the configuration of your site so then you can start poking around.

$ bundle exec irb
2.0.0-p481 :001 > blog
NameError: undefined local variable or method `blog' for main:Object
from (irb):1
2.0.0-p481 :002 > exit
$ middleman console
== LiveReload is waiting for a browser to connect
2.0.0-p481 :001 > blog
=> #<Middleman::Blog::BlogData: [#<Middleman::Blog::BlogArticle: {"title"=>"Emb

etc.

What middleman console does is load up the middleman environment, and then lets you call methods on the current Middleman::Application object. If you are using a middleman extension and they've defined helpers, you can get to them here and start poking around.

Handy things:

config is the middleman config object.

data is the middleman data object, from the data directory

blog is the blog config, if you are using middleman-blog

drafts are the draft articles, if you are using middleman-blog-drafts



来源:https://stackoverflow.com/questions/26163200/middleman-console-how-to-use-it

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!