README.md in shortcode-1.0.0 vs README.md in shortcode-1.0.2

- old
+ new

@@ -25,12 +25,12 @@ ``` $ gem install shortcode ``` -Shortcode is tested against ruby version 1.9.2 and greater as well as jruby, it will not work with ruby 1.8. Shortcode rails integration is tested against -Rails versions 3.0, 3.1, 3.2, 4.0, and 4.1. +Shortcode is tested against ruby version 1.9.3, 2.0, 2.1, and 2.2 as well as jruby, it will not work with ruby 1.8. Shortcode rails integration is tested against +Rails versions 3.1, 3.2, 4.0, 4.1 and 4.2. ## Usage ### Example @@ -38,10 +38,21 @@ ```ruby Shortcode.process("[quote]Hello World[/quote]") ``` +### Tags + +Any tags you wish to use with Shortcode need to be configured in the setup block, there are 2 types of tag, `block_tags` and `self_closing_tags`. Block tags have a matching open and close tag such as `[quote]A quote[/quote]`, self closing tags have no close tag, for example `[gallery]`. To define the tags Shortcode should parse do so in the configuration as follows: + +```ruby +Shortcode.setup do |config| + config.block_tags = [:quote, :list] + config.self_closing_tags = [:gallery, :widget] +end +``` + ### Templates Each shortcode tag needs a template in order to translate the shortcode into html (or other output). Templates can be written in erb, haml or slim and work in a similar way to views in Rails. The main content of a tag is passed via the instance variable `@content`. Any attributes defined on a tag are passed in via an `@attributes` hash, shortcodes can have any number of attributes. For instance a quote shortcode might look like this: @@ -81,15 +92,17 @@ block as strings. #### Templates loaded from the file system Simply create files with the extension or .erb, .haml, or .slim with a filename the same as the shortcode tag, e.g. gallery.html.erb would render a [gallery] shortcode tag. The default -location for template files is `app/views/shortcode_templates`, if you want to load tempaltes from a different location use the `template_path` config option. +location for template files is `app/views/shortcode_templates`, if you want to load templates from a different location use the `template_path` config option. +Note: only 1 template parser is supported at a time, if using haml for instance all templates must be haml. + #### Templates set as configuration options -The alternative way to define tempaltes is to set them using the `templates` config option, this option can take a hash with keys of the same name as the shortcode tags and +The alternative way to define templates is to set them using the `templates` config option, this option can take a hash with keys of the same name as the shortcode tags and values containing a template string. For instance: ```ruby Shortcode.setup do |config| config.templates = { gallery: 'template code' } @@ -97,13 +110,15 @@ ``` If the `templates` config option is set all templates will be loaded from this hash, if a shortcode is encountered without a matching key in the `templates` config option an exception will be raised. +Note: it's NOT possible to load templates from a config option AND from the file system, you must either load all templates from the file system or define all templates in a config option. + ### Custom Helpers -If you wish to use custom helper modules in templates you can do so by specifying the helpers in a setup block which should be an array. Methods in the helper modules will then become available within all tempaltes. +If you wish to use custom helper modules in templates you can do so by specifying the helpers in a setup block which should be an array. Methods in the helper modules will then become available within all templates. ```ruby Shortcode.setup do |config| config.helpers = [CustomHelper, AnotherCustomHelper] end @@ -202,11 +217,11 @@ # a hash of templates passed as strings, if this is set it overrides the # above template_path option. The default is nil config.templates = { gallery: 'template code' } - # an array of helper modules to make available within tempaltes + # an array of helper modules to make available within templates config.helpers = [CustomerHelper] # a list of block tags to support e.g. [quote]Hello World[/quote] config.block_tags = [:quote] @@ -214,10 +229,11 @@ config.self_closing_tags = [:youtube] # the type of quotes to use for attribute values, default is double quotes (") config.attribute_quote_type = '"' - # Allows quotes around attributes to be omitted. Defaults to true (quotes must be present around the value). + # Allows quotes around attributes to be omitted + # Defaults to true, quotes must be present around attribute values config.use_attribute_quotes = true end ```