Permalink
Browse files

Resolving compatibility issues with REE 1.8.6

  • Loading branch information...
paneq committed Jun 7, 2009
1 parent 8fc7e3c commit b2df032ca7f056e304307ddb9122d784943ab545
@@ -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
#
@@ -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
@@ -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
@@ -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 %>
@@ -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 %>
@@ -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 %>
@@ -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
@@ -113,7 +112,8 @@
config.after_initialize do
class Date
include DateExtensions
end
end

end

end
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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"
@@ -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
Oops, something went wrong.

0 comments on commit b2df032

Please sign in to comment.