simple_show 0.0.6 → 0.0.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -55,9 +55,11 @@ module SimpleShow
55
55
  else
56
56
  value = options[:format] % value
57
57
  end
58
- elsif (helper = %w[to_currency to_human to_human_size to_percentage to_phone with_delimiter with_precision].detect{|e| options[e.to_sym].present?})
59
- options[helper.to_sym] = {} unless options[helper.to_sym].is_a? Hash
60
- value = @binding.send("number_#{helper}", value, options[helper.to_sym])
58
+ elsif (helper = (SimpleShow.helpers.keys & options.keys).first).present?
59
+ args = []
60
+ args << value
61
+ args << options[helper] if options[helper].is_a? Hash
62
+ value = @binding.send(SimpleShow.helpers[helper], *args)
61
63
  end
62
64
  end
63
65
 
@@ -1,3 +1,3 @@
1
1
  module SimpleShow
2
- VERSION = "0.0.6"
2
+ VERSION = "0.0.7"
3
3
  end
data/lib/simple_show.rb CHANGED
@@ -43,6 +43,17 @@ module SimpleShow
43
43
  mattr_accessor :clear_on_close
44
44
  @@clear_on_close = true
45
45
 
46
+ mattr_accessor :helpers
47
+ @@helpers = {
48
+ :to_currency => :number_to_currency,
49
+ :to_human => :number_to_human,
50
+ :to_human_size => :number_to_human_size,
51
+ :to_percentage => :number_to_percentage,
52
+ :to_phone => :number_to_phone,
53
+ :with_delimiter => :number_with_delimiter,
54
+ :with_precision => :number_with_precision
55
+ }
56
+
46
57
  # Default way to setup SimpleShow. Run rails generate simple_show:install
47
58
  # to create a fresh initializer with all configuration values.
48
59
  def self.setup
data/test/test_helper.rb CHANGED
@@ -43,6 +43,19 @@ end
43
43
 
44
44
  ################################################################################
45
45
 
46
+ module ActionView
47
+ module Helpers
48
+ module TagHelper
49
+ def piglatin(str)
50
+ str[1..-1] + str[0,1] + 'ay'
51
+ end
52
+ end
53
+ end
54
+ end
55
+
56
+ ################################################################################
57
+
58
+
46
59
  class SimpleShowTestCase < ActiveSupport::TestCase
47
60
  include SimpleShow::ApplicationHelper
48
61
  include ActionController::RecordIdentifier
@@ -4,6 +4,9 @@ class SimpleShowValueTest < SimpleShowTestCase
4
4
 
5
5
  def setup
6
6
  super
7
+ SimpleShow.setup do |config|
8
+ config.helpers[:to_piglatin] = :piglatin
9
+ end
7
10
  @doc = Nokogiri::HTML.fragment(
8
11
  simple_show_for @philip do |s|
9
12
  o = ActiveSupport::SafeBuffer.new
@@ -17,6 +20,8 @@ class SimpleShowValueTest < SimpleShowTestCase
17
20
  o += s.show :name, :format => '%20s'
18
21
  o += s.show :to_currency, :value => '12345.67', :to_currency => true
19
22
  o += s.show :with_delimeter, :value => '12345.67', :with_delimiter => true
23
+ o += s.show :with_delimeter, :value => '12345.67', :with_delimiter => {:delimiter => ' '}
24
+ o += s.show :custom_helper, :value => 'piglatin', :to_piglatin => true
20
25
  o
21
26
  end
22
27
  )
@@ -45,9 +50,14 @@ class SimpleShowValueTest < SimpleShowTestCase
45
50
  assert_equal ' Philip Hallstrom', @doc.css('span.value')[7].text
46
51
  end
47
52
 
48
- test 'number helpers' do
53
+ test 'default helpers' do
49
54
  assert_equal '$12,345.67', @doc.css('span.value')[8].text
50
55
  assert_equal '12,345.67', @doc.css('span.value')[9].text
56
+ assert_equal '12 345.67', @doc.css('span.value')[10].text
57
+ end
58
+
59
+ test 'custom helpers' do
60
+ assert_equal 'iglatinpay', @doc.css('span.value')[11].text
51
61
  end
52
62
 
53
63
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: simple_show
3
3
  version: !ruby/object:Gem::Version
4
- hash: 19
4
+ hash: 17
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 6
10
- version: 0.0.6
9
+ - 7
10
+ version: 0.0.7
11
11
  platform: ruby
12
12
  authors:
13
13
  - Philip Hallstrom
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-08-13 00:00:00 Z
18
+ date: 2011-08-14 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: "SimpleShow is to #show what SimpleForm is to #edit"