Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ Shortcode.process("[quote]Hello World[/quote]")
Shortcode.setup do |config|

# the template parser to use
config.template_parser = :haml # :erb or :haml supported, :haml is default
config.template_parser = :haml # :erb, :haml, :slim supported, :haml is default

# location of the template files, default is "app/views/shortcode_templates"
config.template_path = "support/templates/haml"
Expand Down
5 changes: 5 additions & 0 deletions lib/shortcode.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
require 'parslet'
require 'haml'

begin
require 'slim'
rescue LoadError; end

require 'erb'

module Shortcode
Expand Down
4 changes: 2 additions & 2 deletions lib/shortcode/configuration.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
class Shortcode::Configuration
# Sets the template parser to use, supports :erb and :haml, default is :haml
# Sets the template parser to use, supports :erb, :haml, and :slim, default is :haml
attr_accessor :template_parser

# Sets the template parser to use, supports :erb and :haml, default is :haml
# Sets the path to search for template files
attr_accessor :template_path

# Allows templates to be set from strings rather than read from the filesystem
Expand Down
2 changes: 2 additions & 0 deletions lib/shortcode/tag.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def render

def render_template
case Shortcode.configuration.template_parser
when :slim
Slim::Template.new { markup }.render(self)
when :haml
Haml::Engine.new(markup, ugly: true).render(binding)
when :erb
Expand Down
1 change: 1 addition & 0 deletions shortcode.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "coveralls"
spec.add_development_dependency "slim", "~> 2.0"
end
16 changes: 16 additions & 0 deletions spec/rails_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,25 @@
describe "rails helpers" do

let(:template) { load_fixture :rails_helper }
let(:slim_output) { load_fixture :rails_helper_output_slim, :html }
let(:haml_output) { load_fixture :rails_helper_output_haml, :html }
let(:erb_output) { load_fixture :rails_helper_output_erb, :html }

describe "slim" do

before(:each) do
Shortcode.setup do |config|
config.template_parser = :slim
config.template_path = File.join File.dirname(__FILE__), "support/templates/slim"
end
end

it "are accessible within slim templates" do
Shortcode.process(template).gsub("\n",'').should == slim_output.gsub("\n",'')
end

end

describe "haml" do

it "are accessible within haml templates" do
Expand Down
1 change: 1 addition & 0 deletions spec/support/fixtures/rails_helper_output_slim.html
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<i>blah</i>
1 change: 1 addition & 0 deletions spec/support/templates/slim/rails_helper.html.slim
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
= content_tag :i, @content