Skip to content
Html snippets shared across pages
Ruby JavaScript
Pull request Compare This branch is 43 commits ahead, 69 commits behind simplelogica:master.
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.
app
config
db
features
lib
public
spec
.gitignore
readme.md
refinerycms-snippets.gemspec

readme.md

Snippets engine for Refinery CMS.

About

Snippets allows you to relate one or more html blocks or erb templates to any page in Refinery. These are attached to the page parts, before or after the its html body.

Requirements

  • RefineryCMS with 'Pages' engine (refinerycms-pages >= 0.9.9.1)

TODO

to 1.0

  • Snippet selector in page administration. -- done
  • Save and Continue button -- done
  • Attaching snippet to page part directly through administration, without overriding view template -- done
  • Documentation
  • Tests

to 2.0

  • custom attributes for snippet (id, classes etc)
  • support for dynamic snippets (erb templates, forms etc) -- done
  • improve UI
  • inheritance and clone

Install

Add this line to your applications Gemfile

gem 'refinerycms-snippets', '~> 0.4.1'

Next run

bundle install
rails g refinerycms_snippets
rake db:migrate

Usage

  • Create Snippet on /refinery/snippets
  • Now you can attach snippet to page when you click Edit this page on /refinery/pages. In the Snippets tab you can select the part to which you want to attach the block and add it after and/or before the html body of the part.
  • Next you can use content_of(@page, :part) to print the body of the part and the snippets attached to it in the pages views.
  • You have some other interesting methods to work with snippets:
    • page.snippets: returns all the snippets attached to all the parts of page.
    • part.after: returns all the snippets attached after the html body of part.
    • part.before: returns all the snippets attached before the html body of part.
    • snippet.pages: returns all pages to whose parts is snippet attached.
    • snippet.before?(part): returns true if snippet is attached before part body.
    • snippet.after?(part): return true if snippet is attached after part body.

ERB templates usage

Snippets search for templates in RAILS_VIEWS_PATH/shared/snippets. The snippet searchs for a file with its same name but with all non A-Za-z0-9 characters changed to underscores. If this file exists, snippet html body is ignored and the template is rendered in its place.

For example, a template with title "VIP clients: photos" would search in "app/views/shared/snippets" for a file named "vip_clients_photos.html.erb"; "Country & region banners: España" for "country_region_banners_espa_na" and so on.

Templates are normal erb files. If you want to add complex logic to them I suggest the use of Cells.

Screenshots

Create/Edit Snippet

Donate

Feel free buy me some gift ;-) http://www.amazon.com/gp/registry/wishlist/1BBMUW9DDYXFF

Something went wrong with that request. Please try again.