Module: Stratus::Filters
- Defined in:
- lib/stratus/filters.rb
Constant Summary collapse
- EXTS =
Moved to base resource… def last(content)
return nil unless content.is_a? Hash and content.has_key?('collection_type') collection = Stratus::Generator::LiquidContext.site_data[content['collection_type']] collection.lastend
def prev(content)
return nil unless content.is_a? Hash and content.has_key?('collection_type') collection = Stratus::Generator::LiquidContext.site_data[content['collection_type']] collection.each_with_index do |c,i| return collection[(i - 1)] if c.slug == content['slug'] end nilend
def next(content)
return nil unless content.is_a? Hash and content.has_key?('collection_type') collection = Stratus::Generator::LiquidContext.site_data[content['collection_type']] collection.each_with_index do |c,i| return collection[(i + 1)] if c.slug == content['slug'] end nilend
def first(content)
return nil unless content.is_a? Hash and content.has_key?('collection_type') collection = Stratus::Generator::LiquidContext.site_data[content['collection_type']] collection.firstend
{ '.rb' => 'ruby', '.css' => 'css', '.js' => 'javascript', '.html' => 'html', '.xml' => 'html' }
- LANG_BY_EXT =
Hash.new {|h,k| h[k] = EXTS.fetch(k, 'text') }
Instance Method Summary collapse
- #date_to_xmlschema(date) ⇒ Object
- #number_of_words(input) ⇒ Object
- #short_date(date) ⇒ Object
- #sourcecode(input) ⇒ Object
- #uri(input) ⇒ Object
-
#uri_rel(input) ⇒ Object
deprecated!.
- #url(input) ⇒ Object
- #xml_escape(input) ⇒ Object
Instance Method Details
#date_to_xmlschema(date) ⇒ Object
13 14 15 |
# File 'lib/stratus/filters.rb', line 13 def date_to_xmlschema(date) date.xmlschema end |
#number_of_words(input) ⇒ Object
21 22 23 24 25 26 |
# File 'lib/stratus/filters.rb', line 21 def number_of_words(input) s = strip_html(CGI::unescapeHTML(input)) s.gsub!(/[\w|\']+/, 'X') s.gsub!(/\W+/, '') s.length end |
#short_date(date) ⇒ Object
5 6 7 8 9 10 11 |
# File 'lib/stratus/filters.rb', line 5 def short_date(date) if date.respond_to? :strftime date.strftime('%m/%d/%Y') else "<!-- ??/??/???? -->" end end |
#sourcecode(input) ⇒ Object
68 69 70 71 72 73 74 75 |
# File 'lib/stratus/filters.rb', line 68 def sourcecode(input) if input.is_a? Hash source = IO.readlines( input['source_path'] ).join %Q|<pre><code class="#{ LANG_BY_EXT[ input['ext'] ]}">#{escape(source)}</code></pre>| else "<pre><code>#{escape(input)}</code></pre>" end end |
#uri(input) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 |
# File 'lib/stratus/filters.rb', line 82 def uri(input) case input when Hash "/#{input['full_path']}" when Array "/#{input[0]['collection_type']}/index.html" when String input.starts_with?('/') ? input : "/#{input}" else "/#{input}" end end |
#uri_rel(input) ⇒ Object
deprecated!
96 97 98 |
# File 'lib/stratus/filters.rb', line 96 def uri_rel(input) uri(input) end |
#url(input) ⇒ Object
77 78 79 80 |
# File 'lib/stratus/filters.rb', line 77 def url(input) base_url = Stratus.setting('base_url', 'http://localhost', 'site') base_url + uri(input) end |
#xml_escape(input) ⇒ Object
17 18 19 |
# File 'lib/stratus/filters.rb', line 17 def xml_escape(input) input.gsub("<", "<").gsub(">", ">") end |