Module: TruncateHtmlText

Defined in:
lib/truncate_html_text/truncate_html_text_helper.rb,
lib/truncate_html_text/engine.rb,
lib/truncate_html_text/version.rb
more...

Overview

Contains code for html text truncate helper

Defined Under Namespace

Classes: Engine

Constant Summary collapse

VERSION =
"0.0.1"

Instance Method Summary collapse

Instance Method Details

#insert_truncate_class(options) ⇒ Object

[View source]

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/truncate_html_text/truncate_html_text_helper.rb', line 10

def insert_truncate_class(options)
  class_name = "truncate"
  if options.key?(:class)
    options[:class] += " #{class_name}"
  elsif options.key?('class')
    options['class'] += " #{class_name}"
  else
    options[:class] = class_name
  end
  if options.key?(:data)
	data=Hash[options[:data].map {|k, v| ["data-"<<k.to_s, v] }]
	options.delete(:data)
	options.merge!(data)
elsif options.key?('data')
	data=Hash[options["data"].map {|k, v| ["data-"<<k.to_s, v] }]
	options.delete("data")
	options.merge!(data)
end
  options
end

#truncate_html_text_tag(*args, &block) ⇒ Object

[View source]

4
5
6
7
8
# File 'lib/truncate_html_text/truncate_html_text_helper.rb', line 4

def truncate_html_text_tag(*args, &block)
  options = insert_truncate_class(args.extract_options!)
  args << options
  (*args, &block)
end