texthelpers 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/lib/texthelpers.rb CHANGED
@@ -1,2 +1,2 @@
1
1
  require "texthelpers/version"
2
- require 'texthelpers/railtie' if defined?(Rails)
2
+ require "texthelpers/railtie" if defined?(Rails)
@@ -0,0 +1,8 @@
1
+ require 'texthelpers/view_helpers'
2
+ module Texthelpers
3
+ class Railtie < Rails::Railtie
4
+ initializer "texthelpers.view_helpers" do
5
+ ActionView::Base.send :include, ViewHelpers
6
+ end
7
+ end
8
+ end
@@ -1,3 +1,3 @@
1
1
  module Texthelpers
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -0,0 +1,39 @@
1
+ module Texthelpers
2
+ module ViewHelpers
3
+ def title_for(page, options = {})
4
+ options[:field] ||= "title"
5
+ begin
6
+ title = page.send("#{options[:field]}_#{I18n.locale}")
7
+ # Return default language title if no translation available
8
+ if title.blank?
9
+ title = page.send("#{options[:field]}_#{I18n.default_locale.to_s}")
10
+ end
11
+
12
+ title
13
+ rescue
14
+ nil
15
+ end
16
+ end
17
+
18
+ def text_for(page, options = {})
19
+ options[:markdown] ||= "yes"
20
+ options[:field] ||= "text"
21
+
22
+ text = page.send("#{options[:field]}_#{I18n.locale}")
23
+
24
+ if text.blank?
25
+ text = page.send("#{options[:field]}_#{I18n.default_locale.to_s}")
26
+ end
27
+
28
+ if options[:truncate]
29
+ text = truncate text, :length => options[:truncate]
30
+ end
31
+
32
+ if options[:markdown] == "yes"
33
+ raw BlueCloth.new(raw text).to_html
34
+ else
35
+ text
36
+ end
37
+ end
38
+ end
39
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: texthelpers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -24,7 +24,9 @@ files:
24
24
  - README.md
25
25
  - Rakefile
26
26
  - lib/texthelpers.rb
27
+ - lib/texthelpers/railtie.rb
27
28
  - lib/texthelpers/version.rb
29
+ - lib/texthelpers/view_helpers.rb
28
30
  - texthelpers.gemspec
29
31
  homepage: ''
30
32
  licenses: []