safai 0.0.19 → 0.0.20

Sign up to get free protection for your applications and to get access to all the features.
data/init.rb CHANGED
@@ -1 +1 @@
1
- require 'timeline'
1
+ require 'safai'
data/lib/safai/fires.rb CHANGED
@@ -1,4 +1,4 @@
1
- module Timeline
1
+
2
2
  module Fires
3
3
  def self.included(klass)
4
4
  klass.send(:extend, ClassMethods)
@@ -36,4 +36,4 @@ module Timeline
36
36
  end
37
37
  end
38
38
  end
39
- end
39
+
data/lib/safai.rb CHANGED
@@ -1,173 +1,13 @@
1
- module Timeline
2
- end
3
-
4
1
  class Safai
5
2
 
6
- #======================================
7
-
8
- module Helpers
9
-
10
- require 'money'
11
-
12
- def f(ff)
13
- sprintf("%0.02f", ff)
14
- end
15
-
16
- def title(page_title)
17
- content_for(:title) { page_title }
18
- end
19
-
20
- def smart_date(i)
21
- return "" if i.blank?
22
- i.year == Time.now.year ? i.strftime("%d-%b") : i.strftime("%d-%b-%Y")
23
- end
24
-
25
- def smart_due_date(i)
26
- if i == nil
27
- return ""
28
- elsif i.class.to_s == "Time" or i.class.to_s == "ActiveSupport::TimeWithZone"
29
- i = i.to_date
30
- end
31
- if Date.today == i
32
- return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Today</span>"
33
- elsif i - Date.today == 1
34
- return "<span style=\"background-color:#F7FAB9;padding:0px 2px 0px 2px;\">Tomorrow</span>"
35
- elsif Date.today - i > 0.9
36
- return "<span style=\"background-color:#FFC7C7;padding:0px 2px 0px 2px;\">" + smart_date(i) + "</span>"
37
- elsif Date.today - i < 1
38
- return "<span style=\"background-color:#D2FFCC;padding:0px 2px 0px 2px;\">" + smart_date(i) + "</span>"
39
- end
40
- return smart_date(i)
41
- end
42
-
43
- def location_summary(u)
44
- return Safai::Address.to_s(u)
45
- end
46
-
47
- def location_summary_short(u)
48
- return Safai::Address.gist(u)
49
- end
50
-
51
- def location_map(u)
52
- return Safai::Address.map(u, 300, 95)
53
- end
54
-
55
- def amt2(c, amount)
56
- m = Money::Currency.new(c)
57
- amount = sprintf("%0.02f", amount)
58
- if !m.blank?
59
- if !m.symbol.blank?
60
- return "#{m.symbol} #{amount.to_s}".html_safe
61
- end
62
- end
63
- return "#{c} #{amount.to_s}"
64
- end
65
-
66
- end
67
-
68
- #======================================
69
-
70
- module WikiHelpers
71
-
72
- #include HTMLDiff
73
-
74
- def process_html_links(text)
75
- url_re = %r{
76
- (<[^>]+\s+\w+="?)?
77
- (
78
- (?:https?://)? # optional protocol
79
- (?:[-\w]+\.)+ # subdomain/domain parts
80
- (?:com|net|org|edu|gov|biz|int|mil|info|name|museum|coop|aero|[a-z][a-z]) # TLD
81
- (?::\d+)? # Optional port
82
- (?:/(?:(?:[~\w\+@%=-]|(?:[,.;:][^\s$]))+)?)* # Path
83
- (?:\?[\w\+@%&=.;-]+)? # Query String ?foo=bar
84
- (?:\#[\w\-]*)? # Anchor
85
- )
86
- }xi
87
-
88
- # wrap links for html
89
- text.gsub! url_re do
90
- if $1.present?
91
- $&
92
- else
93
- url = $2
94
- unless url =~ /:\/\//
95
- url = "http://" + url
96
- end
97
- "<a href=\"#{url}\">#{url}</a>"
98
- end
99
- end
100
- text.gsub(/<a\s/, '<a target=\"_blank\" ')
101
- end
102
-
103
- def coderay(text)
104
- text.gsub(/\<code( lang="(.+?)")?\>(.+?)\<\/code\>/m) do
105
- content_tag("notextile", CodeRay.scan($3, $2).div(:css => :class))
106
- end
107
-
108
- def markdown(text)
109
- text = sanitize(text, :tags => %w(object param embed))
110
- text.gsub!(/<script.*>.*<\/script>/, '')
111
- if defined? RDiscount
112
- process_html_links RDiscount.new(text, :smart).to_html.gsub(/\n+/, "<br/>")
113
- else
114
- simple_format(process_html_links(text))
115
- end
116
- end
117
-
3
+ module Fires
118
4
  end
119
5
 
120
- module DeviseHelpers
121
-
122
- def resource_name
123
- :user
124
- end
125
-
126
- def resource
127
- @resource ||= User.new
128
- end
129
-
130
- def devise_mapping
131
- @devise_mapping ||= Devise.mappings[:user]
6
+ module Helpers
132
7
  end
133
-
134
- #DEVISE end
135
-
136
- def devise_error_messages!
137
- flash_alerts = []
138
- error_key = 'errors.messages.not_saved'
139
-
140
- if !flash.empty?
141
- flash_alerts.push(flash[:error]) if flash[:error]
142
- flash_alerts.push(flash[:alert]) if flash[:alert]
143
- flash_alerts.push(flash[:notice]) if flash[:notice]
144
- error_key = 'devise.failure.invalid'
145
- end
146
-
147
- return "" if resource.errors.empty? && flash_alerts.empty?
148
- errors = resource.errors.empty? ? flash_alerts : resource.errors.full_messages
149
-
150
- messages = errors.map { |msg| content_tag(:li, msg) }.join
151
- sentence = I18n.t(error_key, :count => errors.count,
152
- :resource => resource.class.model_name.human.downcase)
153
-
154
- html = <<-HTML
155
- <div id="error_explanation">
156
- <h2>#{sentence}</h2>
157
- <ul>#{messages}</ul>
158
- </div>
159
- HTML
160
-
161
- html.html_safe
162
- end
163
8
 
164
- end
165
9
  end
166
10
 
167
- #======================================
168
-
169
- end
170
-
171
11
  require 'money'
172
12
  require 'roo'
173
13
  require 'safai/spreadsheet'
@@ -178,6 +18,6 @@ require 'safai/gravatar'
178
18
  require 'safai/money'
179
19
  require 'safai/date'
180
20
  require 'safai/fires'
181
- ActiveRecord::Base.send :include, Timeline::Fires
182
- ActionView::Base.send :include, Safai::Helpers
183
- ActionView::Base.send :include, Safai::DeviseHelpers
21
+ require 'safai/helpers'
22
+ ActiveRecord::Base.send :include, Safai::Fires
23
+ ActionView::Base.send :include, Safai::Helpers
data/safai.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = 'safai'
3
- s.version = '0.0.19'
3
+ s.version = '0.0.20'
4
4
  s.date = '2010-04-28'
5
5
  s.summary = "Address logic gem"
6
6
  s.description = "A simple hello world gem"
@@ -19,9 +19,10 @@ Gem::Specification.new do |s|
19
19
  "generators/safai/templates/model.rb",
20
20
  "generators/safai/safai_generator.rb",
21
21
  "lib/safai/fires.rb",
22
- "lib/safai/macros.rb",
23
- "safai.gemspec",
24
- "lib/safai/matchers.rb"]
22
+ #"lib/safai/macros.rb",
23
+ "safai.gemspec"#,
24
+ #"lib/safai/matchers.rb"
25
+ ]
25
26
  s.homepage = 'http://rubygems.org/gems/safai'
26
27
  s.required_rubygems_version = '>= 1.3.6'
27
28
  s.add_development_dependency("carmen", '0.2.13')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: safai
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.19
4
+ version: 0.0.20
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -110,9 +110,7 @@ files:
110
110
  - generators/safai/templates/model.rb
111
111
  - generators/safai/safai_generator.rb
112
112
  - lib/safai/fires.rb
113
- - lib/safai/macros.rb
114
113
  - safai.gemspec
115
- - lib/safai/matchers.rb
116
114
  homepage: http://rubygems.org/gems/safai
117
115
  licenses: []
118
116
  post_install_message:
data/lib/safai/macros.rb DELETED
@@ -1,20 +0,0 @@
1
- module Timeline
2
- module Macros
3
- def should_fire_event(event_type, opts = {})
4
- should "fire #{event_type} on #{opts[:on]}" do
5
- matcher = fire_event(event_type, opts)
6
-
7
- assert_accepts matcher, self.class.name.gsub(/Test$/, '').constantize
8
- end
9
- end
10
-
11
- def should_not_fire_event(event_type, opts = {})
12
- should "fire #{event_type} on #{opts[:on]}" do
13
- matcher = fire_event(event_type, opts)
14
-
15
- assert_rejects matcher, self.class.name.gsub(/Test$/, '').constantize
16
- end
17
- end
18
-
19
- end
20
- end
@@ -1,58 +0,0 @@
1
- module Timeline
2
- module Matchers
3
- class FireEvent
4
- def initialize(event_type, opts = {})
5
- @event_type = event_type
6
- @opts = opts
7
- @method = :"fire_#{@event_type}_after_#{@opts[:on]}"
8
- end
9
-
10
- def matches?(subject)
11
- @subject = subject
12
-
13
- defines_callback_method? && setups_up_callback?
14
- end
15
-
16
- def defines_callback_method?
17
- if @subject.instance_methods.include?(@method.to_s)
18
- true
19
- else
20
- @missing = "#{@subject.name} does not respond to #{@method}"
21
- false
22
- end
23
- end
24
-
25
- def setups_up_callback?
26
- callback_chain_name = "after_#{@opts[:on]}_callback_chain"
27
- callback_chain = @subject.send(callback_chain_name)
28
- if callback_chain.any? {|chain| chain.method == @method }
29
- true
30
- else
31
- @missing = "does setup after #{@opts[:on]} callback for #{@method}"
32
- false
33
- end
34
- end
35
-
36
- def description
37
- "fire a #{@event_type} event"
38
- end
39
-
40
- def expectation
41
- expected = "#{@subject.name} to #{description}"
42
- end
43
-
44
- def failure_message
45
- "Expected #{expectation} (#{@missing})"
46
- end
47
-
48
- def negative_failure_message
49
- "Did not expect #{expectation}"
50
- end
51
-
52
- end
53
-
54
- def fire_event(event_type, opts)
55
- FireEvent.new(event_type, opts)
56
- end
57
- end
58
- end