Sha256: b25f69bb23321a81ad1d1208788fa71bf2e6b70ea3bfdb7b2bd0b521757dd116

Contents?: true

Size: 1.12 KB

Versions: 5

Compression:

Stored size: 1.12 KB

Contents

require 'active_support/core_ext/object/inclusion'

module RailsGuides
  module TextileExtensions
    def notestuff(body)
      body.gsub!(/^(IMPORTANT|CAUTION|WARNING|NOTE|INFO)[.:](.*)$/) do |m|
        css_class = $1.downcase
        css_class = 'warning' if css_class.in?(['caution', 'important'])

        result = "<div class='#{css_class}'><p>"
        result << $2.strip
        result << '</p></div>'
        result
      end
    end

    def tip(body)
      body.gsub!(/^TIP[.:](.*)$/) do |m|
        result = "<div class='info'><p>"
        result << $1.strip
        result << '</p></div>'
        result
      end
    end

    def plusplus(body)
      body.gsub!(/\+(.*?)\+/) do |m|
        "<notextile><tt>#{$1}</tt></notextile>"
      end

      # The real plus sign
      body.gsub!('<plus>', '+')
    end

    def code(body)
      body.gsub!(%r{<(yaml|shell|ruby|erb|html|sql|plain)>(.*?)</\1>}m) do |m|
        es = ERB::Util.h($2)
        css_class = $1.in?(['erb', 'shell']) ? 'html' : $1
        %{<notextile><div class="code_container"><code class="#{css_class}">#{es}</code></div></notextile>}
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
railties-3.1.0.rc4 guides/rails_guides/textile_extensions.rb
railties-3.1.0.rc3 guides/rails_guides/textile_extensions.rb
railties-3.1.0.rc2 guides/rails_guides/textile_extensions.rb
railties-3.1.0.rc1 guides/rails_guides/textile_extensions.rb
railties-3.1.0.beta1 guides/rails_guides/textile_extensions.rb