Skip to content

Commit

Permalink
Resolving compatibility issues with REE 1.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
paneq committed Jun 7, 2009
1 parent 8fc7e3c commit b2df032
Show file tree
Hide file tree
Showing 21 changed files with 415 additions and 326 deletions.
84 changes: 51 additions & 33 deletions app/helpers/shadow_helper.rb
@@ -1,6 +1,57 @@
module ShadowHelper
class ShadowOptions < Hash
def initialize
self[:top] = ShadowLmr.new
self[:middle] = ShadowLmr.new
self[:bottom] = ShadowLmr.new
end

def top
self[:top]
end

def middle
self[:middle]
end

def bottom
self[:bottom]
end
end

class ShadowLmr < Hash
def initialize
self[:left] = ShadowText.new
self[:middle] = ShadowText.new
self[:right] = ShadowText.new
end

def left
self[:left]
end

def middle
self[:middle]
end

def right
self[:right]
end
end

class ShadowText < Hash
def initialize
self[:text] = String.new
end

def text
self[:text]
end

def text=(val)
self[:text]=val
end
end
# Creates a table that includes elements created in block and
# surrounds them with inner shadow
#
Expand Down Expand Up @@ -77,39 +128,6 @@ def shadow(*args, &block)
inner_or_outer_shadow(:outer, *args, &block)
end


#
# Helper for creating options for methods to create shadows.
# You can use it as last paramter in *shadow* methods
#
# in ERB template:
# <% opt = shadow_options do |opt| %>
# <% opt[:top][:middle].call :style => 'height:100px;' do %>
# <div>THIS TEXT WILL BE ON TOP MIDDLE SHADOW which will be 100px height</div>
# <% end %>
# <% end %>
#
# opt => {:top => {:middle => {:style => 'height:100px;', :text => "<div>THIS TEXT WILL BE ON TOP MIDDLE SHADOW</div>" } } }
def shadow_options()
raise 'No block given' unless block_given?
output_hash = {}
call_hash = {}
[:top, :middle, :bottom]. each do |vertical|
call_hash[vertical] = {}
output_hash[vertical] = {}
[:left, :middle, :right]. each do |horizontal|
output_hash[vertical][horizontal] = {:text =>nil}
call_hash[vertical][horizontal] = Proc.new do |arg, &block|
output_hash[vertical][horizontal][:text] = capture(&block)
output_hash[vertical][horizontal].merge!(arg) if arg
end
end
end

yield call_hash
output_hash
end

private

# inner_or_outer_shadow(:inner, '80grey', :left, :right ... element-options, table-shadow-boxes-content-hash do ... end
Expand Down
2 changes: 1 addition & 1 deletion app/models/graph_builder.rb
Expand Up @@ -192,7 +192,7 @@ def self.generate_share_report(report)
OpenFlashChart::PieValue.new(val[:value].value(cur), get_label.call(val))
end
graph.tooltip = "#percent# <br> #label# <br> Wartość: #val##{cur.symbol} z #{sum}#{cur.symbol}"
if values.count > 15
if values.size > 15
graph.set_no_labels()
end
graph.colours = COLORS
Expand Down
8 changes: 2 additions & 6 deletions app/views/exchanges/index.html.erb
Expand Up @@ -14,12 +14,8 @@
</ul>
</div>

<% options = shadow_options do |opt| %>
<% opt[:top][:middle].call do %>
<%= tab [[:new, 'Nowy']], :exchange -%>
<% end %>
<% end %>
<% options = ShadowHelper::ShadowOptions.new %>
<% options.top.middle.text = tab([[:new, 'Nowy']], :exchange) %>
<% light_shadow({:class => 'long'}, {}, options) do %>
<% tab_container(:exchange) do %>
Expand Down
10 changes: 3 additions & 7 deletions app/views/exchanges/list.html.erb
Expand Up @@ -57,13 +57,9 @@
<% options = shadow_options do |opt| %>
<% opt[:top][:middle].call do %>
<%= tab [[:new, 'Nowy']], :exchange -%>
<% end %>
<% end %>
<% options = ShadowHelper::ShadowOptions.new %>
<% options.top.middle.text = tab([[:new, 'Nowy']], :exchange) %>
<% light_shadow({:class => 'long'}, {}, options) do %>
<% tab_container(:exchange) do %>
Expand Down
7 changes: 2 additions & 5 deletions app/views/transfers/_kind_of_transfer.html.erb
Expand Up @@ -7,11 +7,8 @@
<% all.shift if @category.nil? %>
<% show = all.first %>
<% options = shadow_options do |opt| %>
<% opt[:top][:middle].call do %>
<%= tab all, :transfer %>
<% end %>
<% end %>
<% options = ShadowHelper::ShadowOptions.new %>
<% options.top.middle.text = tab(all, :transfer) %>
<% light_shadow({:class => 'long'}, {}, options) do %>
<% tab_container(:transfer) do %>
Expand Down
4 changes: 2 additions & 2 deletions config/environment.rb
Expand Up @@ -11,7 +11,6 @@
# Bootstrap the Rails environment, frameworks, and default configuration
require File.join(File.dirname(__FILE__), 'boot')


Rails::Configuration.class_eval do
include FileSiteKeys #defined in preinitializer
end
Expand Down Expand Up @@ -113,7 +112,8 @@
config.after_initialize do
class Date
include DateExtensions
end
end

end

end
Expand Down
15 changes: 15 additions & 0 deletions config/preinitializer.rb
Expand Up @@ -48,4 +48,19 @@ def apply_file_keys
end

end
end



require File.join(File.dirname(__FILE__), '..', 'lib', 'array_extensions.rb')
require File.join(File.dirname(__FILE__), '..', 'lib', 'enumerable_extensions.rb')

if RUBY_VERSION == "1.8.6"
class Array
include ArrayExtensions
include EnumerableExtensions #already includes Enumerable
end
module Enumerable
include EnumerableExtensions
end
end
49 changes: 49 additions & 0 deletions lib/array_extensions.rb
@@ -0,0 +1,49 @@
module ArrayExtensions
def shuffle
array = self.clone
n = array.size
while n > 1 do
n-=1
k = Kernel.rand(n+1)
tmp = array[k]
array[k] = array[n]
array[n] = tmp
end
array
end #unless method_defined?(:shuffle)


def shuffle!
n = self.size
while n > 1 do
n-=1
k = Kernel.rand(n+1)
tmp = self[k]
self[k] = self[n]
self[n] = tmp
end

end #unless method_defined?(:shuffle!)

def comb(n = size)
if size < n or n < 0
elsif n == 0
yield([])
else
self[1..-1].comb(n) do |x|
yield(x)
end
self[1..-1].comb(n - 1) do |x|
yield([first] + x)
end
end
end


def combination(n = size)
array = []
comb(n) {|c| array << c}
array
end

end
18 changes: 18 additions & 0 deletions lib/enumerable_extensions.rb
@@ -0,0 +1,18 @@
module EnumerableExtensions

def max_by(&proc)
max_obj = nil
max_val = nil
is_first = true
each do |obj|
val = proc.call(obj)
if is_first || val > max_val
max_obj = obj
max_val = val
end
is_first = false
end
max_obj
end

end
2 changes: 1 addition & 1 deletion lib/workers/report_worker.rb
Expand Up @@ -16,7 +16,7 @@ def delete_temporary_reports
non_deleted_reports << r
end
end
if reports.count > 0
if reports.size > 0
logger.info "Deleted #{deleted_reports} reports from #{reports.count}"
logger.info "Problems deleting #{non_deleted_reports}" if deleted_reports < reports.count
else
Expand Down
4 changes: 2 additions & 2 deletions test/test_helper.rb
Expand Up @@ -280,7 +280,7 @@ def create_share_report(user, save = true)
r.user = user
r.category = user.categories.first
r.report_view_type = :pie
r.set_period(["10.01.2009".to_date, "17.01.2009".to_date, :LAST_WEEK])
r.set_period(["10-01-2009".to_date, "17-01-2009".to_date, :LAST_WEEK])
r.depth = 5
r.max_categories_values_count = 6
r.name = "Testowy raport"
Expand All @@ -294,7 +294,7 @@ def create_flow_report(user)
r.user = user
add_category_options user, r
r.report_view_type = :text
r.set_period(["10.01.2009".to_date, "17.01.2009".to_date, :LAST_WEEK])
r.set_period(["10-01-2009".to_date, "17-01-2009".to_date, :LAST_WEEK])
r.name = "Testowy raport"
r.save!
r
Expand Down

0 comments on commit b2df032

Please sign in to comment.