RSS Amplifier

Andrew Kvalheim · Nov 14, 2013

2013-11-14

0
Sign in to vote or save

Andrew Kvalheim · andrew.kvalhe.im

I've created middleman-pry to replace Middleman's built-in console with a Pry console:

andrew.kvalhe.im$ middleman console
ruby:Middleman::Application$ 

Pry lets you explore the context of your code as you would a filesystem. A simple ls of Middleman is enlightening:

ruby:Middleman::Application$ ls
Middleman::CoreExtensions::Data::InstanceMethods#methods: data
Middleman::CoreExtensions::Rendering::InstanceMethods#methods:
  current_engine   options_for_ext         resolve_template
  current_engine=  render                  template_extensions
  fetch_layout     render_individual_file  wrap_layout
  locate_layout    render_template
Middleman::Sitemap::InstanceMethods#methods:
  current_page  current_resource  sitemap
Middleman::Application#methods:
  after_build           compass_config      instrument
  after_configuration   configure           logger
  after_render          development?        ready
  before                development_config  root
  before_configuration  full_path           root_path
  before_render         helpers             source_dir
  build?                initialized         to_s
  build_config          inspect
  cache                 instance_available
Middleman::Blog::Helpers#methods:
  blog             blog_instances   current_article   paginate
  blog_controller  blog_month_path  is_blog_article?  tag_path
  blog_day_path    blog_year_path   page_articles   

It's possible to “cd” into the context of any object—for example, this article;

ruby:Middleman::Application$ cd blog.articles.first
ruby:Middleman::Sitemap::Resource$ ls
Middleman::Sitemap::Resource#methods:
  add_metadata     blog_controller=   instrument  request_path  url
  app              destination_path   logger      source_file
  binary?          destination_path=  metadata    store
  blog_controller  ext                path        template?
Middleman::Blog::BlogArticle#methods:
  blog_data     default_summary_generator  previous_article  summary
  blog_options  inspect                    published?        tags
  body          lang                       render            title
  date          next_article               slug            

to view relevant documentation as you explore;

ruby:Middleman::Sitemap::Resource$ show-doc slug
From: lib/middleman-blog/blog_article.rb @ line 192:
Owner: Middleman::Blog::BlogArticle
Visibility: public
Signature: slug()
Number of lines: 5
The “slug” of the article that shows up in its URL. The article slug
is a parameterized version of the {#title} (lowercase, spaces replaced
with dashes, etc) and can be used in the blog permalink as +:title+.
return [String]

and to execute arbitrary code within the current context:

ruby:Middleman::Sitemap::Resource$ slug
= "use-pry-as-the-middleman-console"

Read the original on andrew.kvalhe.im

Comments

Nothing yet. Say the first thing.

    Sign in to join the conversation.