2013-11-14

I’ve cre­ated mid­dle­man-pry to re­place Middleman’s built-in con­sole with a Pry con­sole:

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

Pry lets you ex­plore the con­text of your code as you would a filesys­tem. A simple ls of Middleman is en­light­en­ing:

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 pos­si­ble to cd into the con­text of any ob­ject—for ex­am­ple, this ar­ti­cle;

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 rel­e­vant doc­u­men­ta­tion as you ex­plore;

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 ex­e­cute ar­bi­trary code within the cur­rent con­text:

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