Module: Haml::Helpers::WltExtensions

Includes:
Configuration
Included in:
Haml::Helpers
Defined in:
lib/haml_helpers_wlt_extensions.rb

Instance Method Summary collapse

Methods included from Configuration

#config, config, #defaultLinks, defaultLinks, links_file_path, read_config, read_configuration, read_default_links, valid_location?

Instance Method Details

#excerpt(striphtml = false, length = 30, ellipsis = "…") ⇒ Object



56
57
58
59
60
61
62
63
# File 'lib/haml_helpers_wlt_extensions.rb', line 56

def excerpt striphtml = false, length = 30, ellipsis = ""
  truncate = HTML_Truncator.truncate deep_content.sub_content, length, :ellipsis => ellipsis
  if striphtml
    truncate.gsub(/<[^>]+>/, '')
  else
    truncate.gsub(/<\/?img[^>]*>/, '')
  end
end

#formated_date(date) ⇒ Object



48
49
50
# File 'lib/haml_helpers_wlt_extensions.rb', line 48

def formated_date date
  date.strftime("%d/%m/%Y")
end


15
16
17
# File 'lib/haml_helpers_wlt_extensions.rb', line 15

def link_to name, content, ext = 'html'
  "<a href='#{url_for(content, ext)}'>#{name}</a>"
end

#render(opts = {}) ⇒ Object



43
44
45
46
# File 'lib/haml_helpers_wlt_extensions.rb', line 43

def render opts = {}
  engine = Haml::Engine.new partial_haml_content(opts[:partial]).raw_content
  engine.render self
end

#spanify(str) ⇒ Object



52
53
54
# File 'lib/haml_helpers_wlt_extensions.rb', line 52

def spanify str
  str.gsub(/./) {|c| "<span>#{c}</span>"}
end

#url(content, ext = 'html') ⇒ Object

def link_to_unless condition, name, content, ext = ‘html’

if condition
  if block_given?
    capture_haml &block
  else
    CGI.escape name
  end
else
  link_to name, content, ext
end

end



35
36
37
38
39
40
41
# File 'lib/haml_helpers_wlt_extensions.rb', line 35

def url content, ext = 'html'
  if content.is_a? String
    url_for_string content, ext
  else
    url_for_string content.url, ext
  end
end