Skip to content

Rendering views via HTML::Pipeline in Rails

License

Notifications You must be signed in to change notification settings

cpoms/html_pipeline_rails

 
 

Repository files navigation

HTML::Pipeline for Rails Build Status

Adds support for rendering views via HTML::Pipeline in Rails. GitHub Flavored Markdown in your Rails app!

Installation

Add this line to your Gemfile:

gem 'html_pipeline_rails'

and then run:

$ bundle

All views ending in .md will then be rendered as HTML, with support for ERB.

Example

app/views/layouts/application.html.erb:

<footer>
  <%= render 'shared/footer' %>
</footer>

app/views/shared/footer.md:

## Copyright <%= Time.now.year %> **BigCorp**

All rights reserved.

Cool, eh?

Customization

By default, .md views will run through ERB, and then the MarkdownFilter pipeline. Note that this means anything output from your ERB tags in a .md view will be parsed as Markdown. You can customize the render pipeline like so:

# config/initializers/html_pipeline.rb
HtmlPipelineRails.config do |c|
  c.pipeline = HTML::Pipeline.new([
    HTML::Pipeline::MarkdownFilter,
    HTML::Pipeline::MentionFilter
  ])
end

In this case, @mentions will now be converted to links. See the HTML::Pipeline documentation to learn about the different options.

For the HTML::Pipeline::EmojiFilter, follow the Rake task instructions in the gemoji gem, and set the :asset_root in your config like so:

HtmlPipelineRails.config do |c|
  context = {
    asset_root: '/images',
    # ...
  }

  c.pipeline = HTML::Pipeline.new([
    HTML::Pipeline::EmojiFilter
    # ...
  ], context)
end

Contributing

Run tests with:

bundle
# then
bundle exec rspec
# or
bundle exec guard

About

Rendering views via HTML::Pipeline in Rails

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Ruby 100.0%