Module: Haml::Helpers::WltExtensions

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

Instance Method Summary collapse

Methods included from Wst::Configuration

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

Instance Method Details

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



70
71
72
73
74
75
76
77
# File 'lib/haml_helpers_wlt_extensions.rb', line 70

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



62
63
64
# File 'lib/haml_helpers_wlt_extensions.rb', line 62

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(content, ext)}'>#{name}</a>"
end


19
20
21
# File 'lib/haml_helpers_wlt_extensions.rb', line 19

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

#render(opts = {}) ⇒ Object



52
53
54
55
56
57
58
59
60
# File 'lib/haml_helpers_wlt_extensions.rb', line 52

def render opts = {}
  content = unless opts[:partial].nil?
    partial_haml_content(opts[:partial], false)
  else
    partial_haml_content(opts[:partial_p], true)
  end
  engine = Haml::Engine.new content.raw_content
  engine.render self
end

#spanify(str) ⇒ Object



66
67
68
# File 'lib/haml_helpers_wlt_extensions.rb', line 66

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

#tr(key, lang = nil) ⇒ Object



79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'lib/haml_helpers_wlt_extensions.rb', line 79

def tr key, lang = nil
  l = if lang.nil?
    if content.prefix?
      content.prefix
    else
      'default'
    end
  else
    lang
  end
  if config['translations'].has_key?(l) && config['translations'][l].has_key?(key)
    config['translations'][l][key]
  else
    key
  end
end

#url(content, ext = 'html', prefix = false) ⇒ 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



39
40
41
42
43
44
45
46
# File 'lib/haml_helpers_wlt_extensions.rb', line 39

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

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



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

def url_p content, ext = 'html'
  url content, ext, true
end