middleman 2.0.4 → 2.0.5
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +8 -0
- data/lib/middleman.rb +7 -1
- data/lib/middleman/vendor/padrino-core-0.10.0/.document +5 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/.gitignore +22 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/LICENSE +20 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/README.rdoc +294 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/Rakefile +5 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/bin/padrino +9 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core.rb +119 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/application.rb +259 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/application/rendering.rb +228 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/application/routing.rb +821 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/application/showexceptions.rb +18 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/caller.rb +45 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/cli/adapter.rb +24 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/cli/base.rb +152 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/cli/console.rb +20 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/cli/rake.rb +24 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/cli/rake_tasks.rb +59 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/command.rb +27 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/images/404.png +0 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/images/500.png +0 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/loader.rb +182 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/cz.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/da.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/de.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/en.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/es.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/fr.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/hu.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/it.yml +37 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/ja.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/nl.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/no.yml +31 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/pl.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/pt_br.yml +37 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/ru.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/tr.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/uk.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/zh_cn.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/locale/zh_tw.yml +30 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/logger.rb +344 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/mounter.rb +192 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/reloader.rb +247 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/router.rb +79 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/server.rb +70 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/support_lite.rb +135 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/tasks.rb +23 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/lib/padrino-core/version.rb +15 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/padrino-core.gemspec +38 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/apps/.components +6 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/apps/.gitignore +7 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/apps/complex.rb +27 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/apps/simple.rb +33 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/dependencies/a.rb +9 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/dependencies/b.rb +4 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/dependencies/c.rb +1 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/dependencies/circular/e.rb +13 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/dependencies/circular/f.rb +2 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/dependencies/circular/g.rb +2 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/fixtures/dependencies/d.rb +4 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/helper.rb +101 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_application.rb +83 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_core.rb +79 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_dependencies.rb +44 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_filters.rb +266 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_logger.rb +91 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_mounter.rb +176 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_reloader_complex.rb +66 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_reloader_simple.rb +97 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_rendering.rb +437 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_router.rb +146 -0
- data/lib/middleman/vendor/padrino-core-0.10.0/test/test_routing.rb +1491 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/.document +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/.gitignore +21 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/LICENSE +20 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/README.rdoc +239 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/Rakefile +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers.rb +51 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/asset_tag_helpers.rb +288 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/form_builder/abstract_form_builder.rb +220 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/form_builder/standard_form_builder.rb +43 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/form_helpers.rb +446 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/format_helpers.rb +260 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/cz.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/da.yml +91 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/de.yml +78 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/en.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/es.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/fr.yml +79 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/hu.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/it.yml +85 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/ja.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/nl.yml +78 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/no.yml +91 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/pl.yml +95 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/pt_br.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/ru.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/tr.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/uk.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/zh_cn.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/locale/zh_tw.yml +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/number_helpers.rb +273 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/output_helpers.rb +128 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/output_helpers/abstract_handler.rb +103 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/output_helpers/erb_handler.rb +79 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/output_helpers/haml_handler.rb +64 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/output_helpers/slim_handler.rb +82 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/render_helpers.rb +40 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/tag_helpers.rb +59 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/lib/padrino-helpers/translation_helpers.rb +21 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/padrino-helpers.gemspec +27 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/app.rb +73 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/capture_concat.erb +14 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/capture_concat.haml +12 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/capture_concat.slim +13 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/content_for.erb +11 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/content_for.haml +9 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/content_for.slim +9 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/content_tag.erb +11 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/content_tag.haml +9 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/content_tag.slim +9 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/current_engine.erb +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/current_engine.haml +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/current_engine.slim +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/fields_for.erb +20 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/fields_for.haml +15 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/fields_for.slim +15 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/form_for.erb +56 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/form_for.haml +47 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/form_for.slim +47 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/form_tag.erb +56 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/form_tag.haml +45 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/form_tag.slim +45 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/link_to.erb +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/link_to.haml +4 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/link_to.slim +4 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/mail_to.erb +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/mail_to.haml +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/mail_to.slim +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/meta_tag.erb +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/meta_tag.haml +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/meta_tag.slim +3 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/partials/_erb.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/partials/_haml.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/partials/_slim.slim +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/simple_partial.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/simple_partial.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/markup_app/views/simple_partial.slim +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/app.rb +45 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/current_engine.haml +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/current_engines/_erb.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/current_engines/_haml.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/current_engines/_slim.slim +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/erb/test.erb +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/explicit_engine.haml +5 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/haml/test.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/template/_user.haml +7 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/template/haml_template.haml +1 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/fixtures/render_app/views/template/some_template.haml +2 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/helper.rb +78 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_asset_tag_helpers.rb +320 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_form_builder.rb +998 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_form_helpers.rb +645 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_format_helpers.rb +227 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_number_helpers.rb +136 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_output_helpers.rb +133 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_render_helpers.rb +69 -0
- data/lib/middleman/vendor/padrino-helpers-0.10.0/test/test_tag_helpers.rb +100 -0
- data/lib/middleman/version.rb +1 -1
- data/middleman.gemspec +6 -2
- metadata +218 -67
@@ -0,0 +1,260 @@
|
|
1
|
+
module Padrino
|
2
|
+
module Helpers
|
3
|
+
module FormatHelpers
|
4
|
+
##
|
5
|
+
# Returns escaped text to protect against malicious content
|
6
|
+
#
|
7
|
+
def escape_html(text)
|
8
|
+
Rack::Utils.escape_html(text)
|
9
|
+
end
|
10
|
+
alias h escape_html
|
11
|
+
alias sanitize_html escape_html
|
12
|
+
|
13
|
+
##
|
14
|
+
# Returns escaped text to protect against malicious content
|
15
|
+
# Returns blank if the text is empty
|
16
|
+
#
|
17
|
+
def h!(text, blank_text = ' ')
|
18
|
+
return blank_text if text.nil? || text.empty?
|
19
|
+
h text
|
20
|
+
end
|
21
|
+
|
22
|
+
##
|
23
|
+
# Strips all HTML tags from the html
|
24
|
+
#
|
25
|
+
def strip_tags(html)
|
26
|
+
html.gsub(/<\/?[^>]*>/, "") if html
|
27
|
+
end
|
28
|
+
|
29
|
+
##
|
30
|
+
# Returns text transformed into HTML using simple formatting rules. Two or more consecutive newlines(\n\n) are considered
|
31
|
+
# as a paragraph and wrapped in <p> or your own tags. One newline (\n) is considered as a linebreak and a <br /> tag is appended.
|
32
|
+
# This method does not remove the newlines from the text.
|
33
|
+
#
|
34
|
+
# ==== Examples
|
35
|
+
#
|
36
|
+
# simple_format("hello\nworld") # => "<p>hello<br/>world</p>"
|
37
|
+
# simple_format("hello\nworld", :tag => :div, :class => :foo) # => "<div class="foo">hello<br/>world</div>"
|
38
|
+
#
|
39
|
+
def simple_format(text, options={})
|
40
|
+
t = options.delete(:tag) || :p
|
41
|
+
start_tag = tag(t, options.merge(:open => true))
|
42
|
+
text = text.to_s.dup
|
43
|
+
text.gsub!(/\r\n?/, "\n") # \r\n and \r -> \n
|
44
|
+
text.gsub!(/\n\n+/, "</#{t}>\n\n#{start_tag}") # 2+ newline -> paragraph
|
45
|
+
text.gsub!(/([^\n]\n)(?=[^\n])/, '\1<br />') # 1 newline -> br
|
46
|
+
text.insert 0, start_tag
|
47
|
+
text << "</#{t}>"
|
48
|
+
end
|
49
|
+
|
50
|
+
##
|
51
|
+
# Attempts to pluralize the singular word unless count is 1. If plural is supplied, it will use that when count is > 1,
|
52
|
+
# otherwise it will use the Inflector to determine the plural form
|
53
|
+
#
|
54
|
+
# ==== Examples
|
55
|
+
#
|
56
|
+
# pluralize(2, 'person') => '2 people'
|
57
|
+
#
|
58
|
+
def pluralize(count, singular, plural = nil)
|
59
|
+
"#{count || 0} " + ((count == 1 || count == '1') ? singular : (plural || singular.pluralize))
|
60
|
+
end
|
61
|
+
|
62
|
+
##
|
63
|
+
# Truncates a given text after a given :length if text is longer than :length (defaults to 30).
|
64
|
+
# The last characters will be replaced with the :omission (defaults to "…") for a total length not exceeding :length.
|
65
|
+
#
|
66
|
+
# ==== Examples
|
67
|
+
#
|
68
|
+
# truncate("Once upon a time in a world far far away", :length => 8) => "Once upon..."
|
69
|
+
#
|
70
|
+
def truncate(text, options={})
|
71
|
+
options.reverse_merge!(:length => 30, :omission => "...")
|
72
|
+
if text
|
73
|
+
len = options[:length] - options[:omission].length
|
74
|
+
chars = text
|
75
|
+
(chars.length > options[:length] ? chars[0...len] + options[:omission] : text).to_s
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
##
|
80
|
+
# Truncates words of a given text after a given :length if number of words in text is more than :length (defaults to 30).
|
81
|
+
# The last words will be replaced with the :omission (defaults to "…") for a total number of words not exceeding :length.
|
82
|
+
#
|
83
|
+
# ==== Examples
|
84
|
+
#
|
85
|
+
# truncate_words("Once upon a time in a world far far away", :length => 8) => "Once upon a time in a world far..."
|
86
|
+
#
|
87
|
+
def truncate_words(text, options={})
|
88
|
+
options.reverse_merge!(:length => 30, :omission => "...")
|
89
|
+
if text
|
90
|
+
words = text.split()
|
91
|
+
words[0..(options[:length]-1)].join(' ') + (words.length > options[:length] ? options[:omission] : '')
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
##
|
96
|
+
# Wraps the text into lines no longer than line_width width.
|
97
|
+
# This method breaks on the first whitespace character that does not exceed line_width (which is 80 by default).
|
98
|
+
#
|
99
|
+
# ==== Examples
|
100
|
+
#
|
101
|
+
# word_wrap('Once upon a time', :line_width => 8) => "Once upon\na time"
|
102
|
+
#
|
103
|
+
def word_wrap(text, *args)
|
104
|
+
options = args.extract_options!
|
105
|
+
unless args.blank?
|
106
|
+
options[:line_width] = args[0] || 80
|
107
|
+
end
|
108
|
+
options.reverse_merge!(:line_width => 80)
|
109
|
+
|
110
|
+
text.split("\n").map do |line|
|
111
|
+
line.length > options[:line_width] ? line.gsub(/(.{1,#{options[:line_width]}})(\s+|$)/, "\\1\n").strip : line
|
112
|
+
end * "\n"
|
113
|
+
end
|
114
|
+
|
115
|
+
##
|
116
|
+
# Highlights one or more words everywhere in text by inserting it into a :highlighter string.
|
117
|
+
#
|
118
|
+
# The highlighter can be customized by passing :+highlighter+ as a single-quoted string
|
119
|
+
# with \1 where the phrase is to be inserted (defaults to ’<strong class="highlight">\1</strong>’)
|
120
|
+
#
|
121
|
+
# ==== Examples
|
122
|
+
#
|
123
|
+
# # => Lorem ipsum <strong class="highlight">dolor</strong> sit amet
|
124
|
+
# highlight('Lorem ipsum dolor sit amet', 'dolor')
|
125
|
+
#
|
126
|
+
# # => Lorem ipsum <span class="custom">dolor</span> sit amet
|
127
|
+
# highlight('Lorem ipsum dolor sit amet', 'dolor', :highlighter => '<span class="custom">\1</span>')
|
128
|
+
#
|
129
|
+
def highlight(text, words, *args)
|
130
|
+
options = args.extract_options!
|
131
|
+
options.reverse_merge!(:highlighter => '<strong class="highlight">\1</strong>')
|
132
|
+
|
133
|
+
if text.blank? || words.blank?
|
134
|
+
text
|
135
|
+
else
|
136
|
+
match = Array(words).map { |p| Regexp.escape(p) }.join('|')
|
137
|
+
text.gsub(/(#{match})(?!(?:[^<]*?)(?:["'])[^<>]*>)/i, options[:highlighter])
|
138
|
+
end
|
139
|
+
end
|
140
|
+
|
141
|
+
##
|
142
|
+
# Reports the approximate distance in time between two Time or Date objects or integers as seconds.
|
143
|
+
# Set <tt>include_seconds</tt> to true if you want more detailed approximations when distance < 1 min, 29 secs
|
144
|
+
# Distances are reported based on the following table:
|
145
|
+
#
|
146
|
+
# 0 <-> 29 secs # => less than a minute
|
147
|
+
# 30 secs <-> 1 min, 29 secs # => 1 minute
|
148
|
+
# 1 min, 30 secs <-> 44 mins, 29 secs # => [2..44] minutes
|
149
|
+
# 44 mins, 30 secs <-> 89 mins, 29 secs # => about 1 hour
|
150
|
+
# 89 mins, 29 secs <-> 23 hrs, 59 mins, 29 secs # => about [2..24] hours
|
151
|
+
# 23 hrs, 59 mins, 29 secs <-> 47 hrs, 59 mins, 29 secs # => 1 day
|
152
|
+
# 47 hrs, 59 mins, 29 secs <-> 29 days, 23 hrs, 59 mins, 29 secs # => [2..29] days
|
153
|
+
# 29 days, 23 hrs, 59 mins, 30 secs <-> 59 days, 23 hrs, 59 mins, 29 secs # => about 1 month
|
154
|
+
# 59 days, 23 hrs, 59 mins, 30 secs <-> 1 yr minus 1 sec # => [2..12] months
|
155
|
+
# 1 yr <-> 1 yr, 3 months # => about 1 year
|
156
|
+
# 1 yr, 3 months <-> 1 yr, 9 months # => over 1 year
|
157
|
+
# 1 yr, 9 months <-> 2 yr minus 1 sec # => almost 2 years
|
158
|
+
# 2 yrs <-> max time or date # => (same rules as 1 yr)
|
159
|
+
#
|
160
|
+
# With <tt>include_seconds</tt> = true and the difference < 1 minute 29 seconds:
|
161
|
+
# 0-4 secs # => less than 5 seconds
|
162
|
+
# 5-9 secs # => less than 10 seconds
|
163
|
+
# 10-19 secs # => less than 20 seconds
|
164
|
+
# 20-39 secs # => half a minute
|
165
|
+
# 40-59 secs # => less than a minute
|
166
|
+
# 60-89 secs # => 1 minute
|
167
|
+
#
|
168
|
+
# ==== Examples
|
169
|
+
#
|
170
|
+
# from_time = Time.now
|
171
|
+
# distance_of_time_in_words(from_time, from_time + 50.minutes) # => about 1 hour
|
172
|
+
# distance_of_time_in_words(from_time, 50.minutes.from_now) # => about 1 hour
|
173
|
+
# distance_of_time_in_words(from_time, from_time + 15.seconds) # => less than a minute
|
174
|
+
# distance_of_time_in_words(from_time, from_time + 15.seconds, true) # => less than 20 seconds
|
175
|
+
# distance_of_time_in_words(from_time, 3.years.from_now) # => about 3 years
|
176
|
+
# distance_of_time_in_words(from_time, from_time + 60.hours) # => about 3 days
|
177
|
+
# distance_of_time_in_words(from_time, from_time + 45.seconds, true) # => less than a minute
|
178
|
+
# distance_of_time_in_words(from_time, from_time - 45.seconds, true) # => less than a minute
|
179
|
+
# distance_of_time_in_words(from_time, 76.seconds.from_now) # => 1 minute
|
180
|
+
# distance_of_time_in_words(from_time, from_time + 1.year + 3.days) # => about 1 year
|
181
|
+
# distance_of_time_in_words(from_time, from_time + 3.years + 6.months) # => over 3 years
|
182
|
+
# distance_of_time_in_words(from_time, from_time + 4.years + 9.days + 30.minutes + 5.seconds) # => about 4 years
|
183
|
+
#
|
184
|
+
# to_time = Time.now + 6.years + 19.days
|
185
|
+
# distance_of_time_in_words(from_time, to_time, true) # => about 6 years
|
186
|
+
# distance_of_time_in_words(to_time, from_time, true) # => about 6 years
|
187
|
+
# distance_of_time_in_words(Time.now, Time.now) # => less than a minute
|
188
|
+
#
|
189
|
+
def distance_of_time_in_words(from_time, to_time = 0, include_seconds = false, options = {})
|
190
|
+
from_time = from_time.to_time if from_time.respond_to?(:to_time)
|
191
|
+
to_time = to_time.to_time if to_time.respond_to?(:to_time)
|
192
|
+
distance_in_minutes = (((to_time.to_i - from_time.to_i).abs)/60).round
|
193
|
+
distance_in_seconds = ((to_time.to_i - from_time.to_i).abs).round
|
194
|
+
|
195
|
+
I18n.with_options :locale => options[:locale], :scope => :'datetime.distance_in_words' do |locale|
|
196
|
+
case distance_in_minutes
|
197
|
+
when 0..1
|
198
|
+
return distance_in_minutes == 0 ?
|
199
|
+
locale.t(:less_than_x_minutes, :count => 1) :
|
200
|
+
locale.t(:x_minutes, :count => distance_in_minutes) unless include_seconds
|
201
|
+
|
202
|
+
case distance_in_seconds
|
203
|
+
when 0..4 then locale.t :less_than_x_seconds, :count => 5
|
204
|
+
when 5..9 then locale.t :less_than_x_seconds, :count => 10
|
205
|
+
when 10..19 then locale.t :less_than_x_seconds, :count => 20
|
206
|
+
when 20..39 then locale.t :half_a_minute
|
207
|
+
when 40..59 then locale.t :less_than_x_minutes, :count => 1
|
208
|
+
else locale.t :x_minutes, :count => 1
|
209
|
+
end
|
210
|
+
|
211
|
+
when 2..44 then locale.t :x_minutes, :count => distance_in_minutes
|
212
|
+
when 45..89 then locale.t :about_x_hours, :count => 1
|
213
|
+
when 90..1439 then locale.t :about_x_hours, :count => (distance_in_minutes.to_f / 60.0).round
|
214
|
+
when 1440..2529 then locale.t :x_days, :count => 1
|
215
|
+
when 2530..43199 then locale.t :x_days, :count => (distance_in_minutes.to_f / 1440.0).round
|
216
|
+
when 43200..86399 then locale.t :about_x_months, :count => 1
|
217
|
+
when 86400..525599 then locale.t :x_months, :count => (distance_in_minutes.to_f / 43200.0).round
|
218
|
+
else
|
219
|
+
distance_in_years = distance_in_minutes / 525600
|
220
|
+
minute_offset_for_leap_year = (distance_in_years / 4) * 1440
|
221
|
+
remainder = ((distance_in_minutes - minute_offset_for_leap_year) % 525600)
|
222
|
+
if remainder < 131400
|
223
|
+
locale.t(:about_x_years, :count => distance_in_years)
|
224
|
+
elsif remainder < 394200
|
225
|
+
locale.t(:over_x_years, :count => distance_in_years)
|
226
|
+
else
|
227
|
+
locale.t(:almost_x_years, :count => distance_in_years + 1)
|
228
|
+
end
|
229
|
+
end
|
230
|
+
end
|
231
|
+
end
|
232
|
+
|
233
|
+
##
|
234
|
+
# Like distance_of_time_in_words, but where <tt>to_time</tt> is fixed to <tt>Time.now</tt>.
|
235
|
+
#
|
236
|
+
# ==== Examples
|
237
|
+
#
|
238
|
+
# time_ago_in_words(3.minutes.from_now) # => 3 minutes
|
239
|
+
# time_ago_in_words(Time.now - 15.hours) # => 15 hours
|
240
|
+
# time_ago_in_words(Time.now) # => less than a minute
|
241
|
+
#
|
242
|
+
# from_time = Time.now - 3.days - 14.minutes - 25.seconds # => 3 days
|
243
|
+
#
|
244
|
+
def time_ago_in_words(from_time, include_seconds = false)
|
245
|
+
distance_of_time_in_words(from_time, Time.now, include_seconds)
|
246
|
+
end
|
247
|
+
|
248
|
+
##
|
249
|
+
# Used in xxxx.js.erb files to escape html so that it can be passed to javascript from Padrino
|
250
|
+
#
|
251
|
+
# js_escape_html("<h1>Hey</h1>")
|
252
|
+
#
|
253
|
+
def js_escape_html(html_content)
|
254
|
+
return '' unless html_content
|
255
|
+
javascript_mapping = { '\\' => '\\\\', '</' => '<\/', "\r\n" => '\n', "\n" => '\n', "\r" => '\n', '"' => '\\"', "'" => "\\'" }
|
256
|
+
html_content.gsub(/(\\|<\/|\r\n|[\n\r"'])/) { javascript_mapping[$1] }
|
257
|
+
end
|
258
|
+
end # FormatHelpers
|
259
|
+
end # Helpers
|
260
|
+
end # Padrino
|
@@ -0,0 +1,103 @@
|
|
1
|
+
cz:
|
2
|
+
number:
|
3
|
+
# Used in number_with_delimiter()
|
4
|
+
# These are also the defaults for 'currency', 'percentage', 'precision', and 'human'
|
5
|
+
format:
|
6
|
+
# Sets the separator between the units, for more precision (e.g. 1.0 / 2.0 == 0.5)
|
7
|
+
separator: ","
|
8
|
+
# Delimets thousands (e.g. 1,000,000 is a million) (always in groups of three)
|
9
|
+
delimiter: " "
|
10
|
+
# Number of decimals, behind the separator (the number 1 with a precision of 2 gives: 1.00)
|
11
|
+
precision: 3
|
12
|
+
|
13
|
+
# Used in number_to_currency()
|
14
|
+
currency:
|
15
|
+
format:
|
16
|
+
# Where is the currency sign? %u is the currency unit, %n the number (default: $5.00)
|
17
|
+
format: "%n %u"
|
18
|
+
unit: "Kč"
|
19
|
+
# These three are to override number.format and are optional
|
20
|
+
# separator: ","
|
21
|
+
# delimiter: " "
|
22
|
+
precision: 2
|
23
|
+
|
24
|
+
# Used in number_to_percentage()
|
25
|
+
percentage:
|
26
|
+
format:
|
27
|
+
# These three are to override number.format and are optional
|
28
|
+
# separator:
|
29
|
+
delimiter: ""
|
30
|
+
# precision:
|
31
|
+
|
32
|
+
# Used in number_to_precision()
|
33
|
+
precision:
|
34
|
+
format:
|
35
|
+
# These three are to override number.format and are optional
|
36
|
+
# separator:
|
37
|
+
delimiter: ""
|
38
|
+
# precision:
|
39
|
+
|
40
|
+
# Used in number_to_human_size()
|
41
|
+
human:
|
42
|
+
format:
|
43
|
+
# These three are to override number.format and are optional
|
44
|
+
# separator:
|
45
|
+
delimiter: ""
|
46
|
+
precision: 1
|
47
|
+
storage_units:
|
48
|
+
# Storage units output formatting.
|
49
|
+
# %u is the storage unit, %n is the number (default: 2 MB)
|
50
|
+
format: "%n %u"
|
51
|
+
units:
|
52
|
+
byte:
|
53
|
+
one: "Byte"
|
54
|
+
other: "Bytes"
|
55
|
+
kb: "KB"
|
56
|
+
mb: "MB"
|
57
|
+
gb: "GB"
|
58
|
+
tb: "TB"
|
59
|
+
|
60
|
+
# Used in distance_of_time_in_words(), distance_of_time_in_words_to_now(), time_ago_in_words()
|
61
|
+
datetime:
|
62
|
+
distance_in_words:
|
63
|
+
half_a_minute: "půl minutou"
|
64
|
+
less_than_x_seconds:
|
65
|
+
one: "asi před sekundou"
|
66
|
+
other: "asi před %{count} sekundami"
|
67
|
+
x_seconds:
|
68
|
+
one: "sekundou"
|
69
|
+
other: "%{count} sekundami"
|
70
|
+
less_than_x_minutes:
|
71
|
+
one: "před necelou minutou"
|
72
|
+
other: "před ani ne %{count} minutami"
|
73
|
+
x_minutes:
|
74
|
+
one: "minutou"
|
75
|
+
other: "%{count} minutami"
|
76
|
+
about_x_hours:
|
77
|
+
one: "asi hodinou"
|
78
|
+
other: "asi %{count} hodinami"
|
79
|
+
x_days:
|
80
|
+
one: "24 hodinami"
|
81
|
+
other: "%{count} dny"
|
82
|
+
about_x_months:
|
83
|
+
one: "asi měsícem"
|
84
|
+
other: "asi %{count} měsíci"
|
85
|
+
x_months:
|
86
|
+
one: "měsícem"
|
87
|
+
other: "%{count} měsíci"
|
88
|
+
about_x_years:
|
89
|
+
one: "asi rokem"
|
90
|
+
other: "asi %{count} roky"
|
91
|
+
over_x_years:
|
92
|
+
one: "více než před rokem"
|
93
|
+
other: "více než %{count} roky"
|
94
|
+
almost_x_years:
|
95
|
+
one: "skoro rokem"
|
96
|
+
other: "almost %{count} roků"
|
97
|
+
models:
|
98
|
+
errors:
|
99
|
+
template:
|
100
|
+
header:
|
101
|
+
one: "Při ukládání %{model} došlo k chybě a nebylo jej možné uložit"
|
102
|
+
other: "Při ukládání %{model} došlo ke %{count} chybám a nebylo možné jej uložit"
|
103
|
+
body: "Následující pole obsahují chybně vyplněné údaje:"
|
@@ -0,0 +1,91 @@
|
|
1
|
+
da:
|
2
|
+
number:
|
3
|
+
format:
|
4
|
+
separator: ","
|
5
|
+
delimiter: "."
|
6
|
+
precision: 3
|
7
|
+
currency:
|
8
|
+
format:
|
9
|
+
format: "%u %n"
|
10
|
+
unit: "DKK"
|
11
|
+
separator: ","
|
12
|
+
delimiter: "."
|
13
|
+
precision: 2
|
14
|
+
precision:
|
15
|
+
format:
|
16
|
+
# separator:
|
17
|
+
delimiter: ""
|
18
|
+
# precision:
|
19
|
+
human:
|
20
|
+
format:
|
21
|
+
# separator:
|
22
|
+
delimiter: ""
|
23
|
+
precision: 1
|
24
|
+
storage_units:
|
25
|
+
# Storage units output formatting.
|
26
|
+
# %u is the storage unit, %n is the number (default: 2 MB)
|
27
|
+
format: "%n %u"
|
28
|
+
units:
|
29
|
+
byte:
|
30
|
+
one: "Byte"
|
31
|
+
other: "Bytes"
|
32
|
+
kb: "KB"
|
33
|
+
mb: "MB"
|
34
|
+
gb: "GB"
|
35
|
+
tb: "TB"
|
36
|
+
percentage:
|
37
|
+
format:
|
38
|
+
# separator:
|
39
|
+
delimiter: ""
|
40
|
+
# precision:
|
41
|
+
|
42
|
+
datetime:
|
43
|
+
distance_in_words:
|
44
|
+
half_a_minute: "et halvt minut"
|
45
|
+
less_than_x_seconds:
|
46
|
+
one: "mindre end et sekund"
|
47
|
+
other: "mindre end %{count} sekunder"
|
48
|
+
x_seconds:
|
49
|
+
one: "et sekund"
|
50
|
+
other: "%{count} sekunder"
|
51
|
+
less_than_x_minutes:
|
52
|
+
one: "mindre end et minut"
|
53
|
+
other: "mindre end %{count} minutter"
|
54
|
+
x_minutes:
|
55
|
+
one: "et minut"
|
56
|
+
other: "%{count} minutter"
|
57
|
+
about_x_hours:
|
58
|
+
one: "cirka en time"
|
59
|
+
other: "cirka %{count} timer"
|
60
|
+
x_days:
|
61
|
+
one: "en dag"
|
62
|
+
other: "%{count} dage"
|
63
|
+
about_x_months:
|
64
|
+
one: "cirka en måned"
|
65
|
+
other: "cirka %{count} måneder"
|
66
|
+
x_months:
|
67
|
+
one: "en måned"
|
68
|
+
other: "%{count} måneder"
|
69
|
+
about_x_years:
|
70
|
+
one: "cirka et år"
|
71
|
+
other: "cirka %{count} år"
|
72
|
+
over_x_years:
|
73
|
+
one: "mere end et år"
|
74
|
+
other: "mere end %{count} år"
|
75
|
+
almost_x_years:
|
76
|
+
one: "næsten et år"
|
77
|
+
other: "næsten %{count} years"
|
78
|
+
prompts:
|
79
|
+
second: "Sekund"
|
80
|
+
minute: "Minut"
|
81
|
+
hour: "Time"
|
82
|
+
day: "Dag"
|
83
|
+
month: "Måned"
|
84
|
+
year: "År"
|
85
|
+
models:
|
86
|
+
errors:
|
87
|
+
template:
|
88
|
+
header:
|
89
|
+
one: "En fejl forhindrede %{model} i at blive gemt"
|
90
|
+
other: "%{count} fejl forhindrede denne %{model} i at blive gemt"
|
91
|
+
body: "Der var problemer med følgende felter:"
|