Module: Hamlit::RailsHelpers
- Extended by:
- RailsHelpers
- Includes:
- Helpers
- Included in:
- RailsHelpers
- Defined in:
- lib/hamlit/rails_helpers.rb
Constant Summary collapse
- DEFAULT_PRESERVE_TAGS =
%w[textarea pre code].freeze
Instance Method Summary collapse
- #capture_haml(*args, &block) ⇒ Object
- #find_and_preserve(input = nil, tags = DEFAULT_PRESERVE_TAGS, &block) ⇒ Object
- #precede(str, &block) ⇒ Object
- #preserve(input = nil, &block) ⇒ Object
- #succeed(str, &block) ⇒ Object
- #surround(front, back = front, &block) ⇒ Object
Instance Method Details
#capture_haml(*args, &block) ⇒ Object
46 47 48 |
# File 'lib/hamlit/rails_helpers.rb', line 46 def capture_haml(*args, &block) capture(*args, &block) end |
#find_and_preserve(input = nil, tags = DEFAULT_PRESERVE_TAGS, &block) ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/hamlit/rails_helpers.rb', line 12 def find_and_preserve(input = nil, = DEFAULT_PRESERVE_TAGS, &block) return find_and_preserve(capture_haml(&block), input || ) if block = .each_with_object('') do |t, s| s << '|' unless s.empty? s << Regexp.escape(t) end re = /<(#{})([^>]*)>(.*?)(<\/\1>)/im input.to_s.gsub(re) do |s| s =~ re # Can't rely on $1, etc. existing since Rails' SafeBuffer#gsub is incompatible "<#{$1}#{$2}>#{preserve($3)}</#{$1}>" end end |
#precede(str, &block) ⇒ Object
38 39 40 |
# File 'lib/hamlit/rails_helpers.rb', line 38 def precede(str, &block) "#{escape_once(str)}#{capture_haml(&block).chomp}\n".html_safe end |
#preserve(input = nil, &block) ⇒ Object
27 28 29 30 |
# File 'lib/hamlit/rails_helpers.rb', line 27 def preserve(input = nil, &block) return preserve(capture_haml(&block)) if block super end |
#succeed(str, &block) ⇒ Object
42 43 44 |
# File 'lib/hamlit/rails_helpers.rb', line 42 def succeed(str, &block) "#{capture_haml(&block).chomp}#{escape_once(str)}\n".html_safe end |
#surround(front, back = front, &block) ⇒ Object
32 33 34 35 36 |
# File 'lib/hamlit/rails_helpers.rb', line 32 def surround(front, back = front, &block) output = capture_haml(&block) "#{escape_once(front)}#{output.chomp}#{escape_once(back)}\n".html_safe end |