florrick 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 20ab91439eaf4ce4d05675e501a0667f48138633
4
- data.tar.gz: 0df8702cce5af859de517f3e34a645608aa9b993
3
+ metadata.gz: d99e1315bb37101ae10cb3e6dbbb72abc0af64e5
4
+ data.tar.gz: 8373a863cb8713c6bddeb554cfa0f127acfa21e1
5
5
  SHA512:
6
- metadata.gz: df6f287a92029579b87b8589e140792ed7f747464666718ab2e177fa7a40b91eff1a7dc03aa5b13799a6a668394f89fef60ec8f79cf3f4489901b82adefca782
7
- data.tar.gz: 64a594f1d4b80a821f09117b340c11ac4ce91d72c85d0014cc7193898be33e7cb57c13991f68ed62e9c43271d2d279e2c7001246870e7710e2cab3c1149aed54
6
+ metadata.gz: 86cae527b35f612d7cbf198c0e0756c33410f9e2aa06cb10b1306d46113a3693702a4b53f5e9788e92efdc3080e0984f95f58f573b8c0d4588ded828b8de81e0
7
+ data.tar.gz: 9ffeda401001ade5e88b2b67dbf4d8c95889d173e0dcc2b8416ded9e96a895a03088c1cbf7d907451789bcc67779e6eb0cb1d16b80cdfa6521e3ff6c17fa6bf7
@@ -1,8 +1,8 @@
1
1
  module Florrick
2
2
  class Builder
3
-
3
+
4
4
  VALID_EXPORT_TYPES = [String, Numeric, Date, Time]
5
-
5
+
6
6
  attr_reader :original_string, :objects
7
7
 
8
8
  def initialize(string, objects = {})
@@ -12,15 +12,21 @@ module Florrick
12
12
 
13
13
  def output
14
14
  string = @original_string.dup
15
- string.gsub(/(\{\{([(\w+)\.]+)\}\})/) do
15
+ string.gsub(/(\{\{([(\w+)\.]+)(?>\ ?\|\ ?([\w\-\+\ \!\?\[\]\(\)]+))?\}\})/) do
16
+ original_string = $1
17
+ fallback_string = $3
16
18
  parts = $2.split('.')
17
19
  final_string = nil
18
20
  previous_object = @objects[parts.shift.to_sym]
19
- final_string = $1 if previous_object.nil?
21
+
22
+ if previous_object.nil?
23
+ final_string = fallback_string || original_string
24
+ end
25
+
20
26
  until final_string
21
27
  # get the latest part
22
28
  if var = parts.shift
23
- # if the previous object is suitable for string interpolation, we can
29
+ # if the previous object is suitable for string interpolation, we can
24
30
  # pass the var to it and get out a string or an integer.
25
31
  if previous_object.respond_to?(:string_interpolation_value_for)
26
32
  if previous_object.class.string_interpolation_for?(var)
@@ -33,14 +39,14 @@ module Florrick
33
39
  previous_object = previous_object.send(var)
34
40
  else
35
41
  # can't do this :(
36
- final_string = $1
42
+ final_string = fallback_string || original_string
37
43
  end
38
44
  elsif VALID_EXPORT_TYPES.any? { |t| previous_object.is_a?(t)}
39
45
  previous_object = Florrick::Formatter.convert(var, previous_object)
40
46
  else
41
47
  # does not respond to string_interpolation_value_for and isn't a valid object,
42
48
  # we can't do anything here just return the passed value.
43
- final_string = $1
49
+ final_string = fallback_string || original_string
44
50
  end
45
51
  else
46
52
  # we're at the end now, if we can return the previous object, lets do it otherwise
@@ -48,7 +54,7 @@ module Florrick
48
54
  if VALID_EXPORT_TYPES.any? { |t| previous_object.is_a?(t)}
49
55
  final_string = previous_object.to_s
50
56
  else
51
- final_string = $1
57
+ final_string = fallback_string || original_string
52
58
  end
53
59
  end
54
60
  end
@@ -1,3 +1,3 @@
1
1
  module Florrick
2
- VERSION = '1.0.0'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: florrick
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Cooke
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-02 00:00:00.000000000 Z
11
+ date: 2015-01-31 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A Rails extension for providing awesome user-initiated string interpolation
14
14
  email:
@@ -26,7 +26,8 @@ files:
26
26
  - lib/florrick/railtie.rb
27
27
  - lib/florrick/version.rb
28
28
  homepage: https://github.com/adamcooke/florrick
29
- licenses: []
29
+ licenses:
30
+ - MIT
30
31
  metadata: {}
31
32
  post_install_message:
32
33
  rdoc_options: []
@@ -44,9 +45,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
44
45
  version: '0'
45
46
  requirements: []
46
47
  rubyforge_project:
47
- rubygems_version: 2.2.0
48
+ rubygems_version: 2.2.2
48
49
  signing_key:
49
50
  specification_version: 4
50
51
  summary: A Rails extension for providing awesome user-initiated string interpolation
51
52
  test_files: []
52
- has_rdoc: