Skip to content

Commit

Permalink
Easel Helpers => Viewaide
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuaclayton committed Jan 10, 2010
1 parent a95ea45 commit c1dbca3
Show file tree
Hide file tree
Showing 33 changed files with 116 additions and 151 deletions.
31 changes: 0 additions & 31 deletions Manifest
@@ -1,31 +0,0 @@
easel_helpers.gemspec
lib/easel_helpers/helpers/date_helper.rb
lib/easel_helpers/helpers/form_helper.rb
lib/easel_helpers/helpers/grid_helper.rb
lib/easel_helpers/helpers/jquery_helper.rb
lib/easel_helpers/helpers/link_helper.rb
lib/easel_helpers/helpers/message_helper.rb
lib/easel_helpers/helpers/navigation_helper.rb
lib/easel_helpers/helpers/rjs_helper.rb
lib/easel_helpers/helpers/structure_helper.rb
lib/easel_helpers/helpers/table_helper.rb
lib/easel_helpers/helpers.rb
lib/easel_helpers/rails_partial_caching.rb
lib/easel_helpers.rb
Manifest
MIT-LICENSE
rails/init.rb
Rakefile
README.textile
tasks/easel_helpers_tasks.rake
test/date_helper_test.rb
test/form_helper_test.rb
test/grid_helper_test.rb
test/jquery_helper_test.rb
test/link_helper_test.rb
test/message_helper_test.rb
test/navigation_helper_test.rb
test/rjs_helper_test.rb
test/structure_helper_test.rb
test/table_helper_test.rb
test/test_helper.rb
2 changes: 1 addition & 1 deletion README.textile
@@ -1,3 +1,3 @@
h1. Easel Helpers
h1. Viewaide

Copyright (c) 2009 Josh Clayton, released under the MIT license
6 changes: 3 additions & 3 deletions Rakefile
Expand Up @@ -3,9 +3,9 @@ require "rake/testtask"
require "rcov/rcovtask"
require "echoe"

Echoe.new("easel_helpers", "0.3.0") do |p|
p.description = "Fusionary Rails View Helpers"
p.url = "http://github.com/fusionary/easel_helpers"
Echoe.new("viewaide", "0.3.0") do |p|
p.description = "Making your views easier"
p.url = "http://github.com/joshuaclayton/viewaide"
p.author = "Joshua Clayton"
p.email = "joshua.clayton@gmail.com"
p.ignore_pattern = ["tmp/*"]
Expand Down
3 changes: 0 additions & 3 deletions lib/easel_helpers.rb

This file was deleted.

40 changes: 0 additions & 40 deletions lib/easel_helpers/rails_partial_caching.rb

This file was deleted.

3 changes: 3 additions & 0 deletions lib/viewaide.rb
@@ -0,0 +1,3 @@
require "hpricot"
require "viewaide/helpers"
require "viewaide/rails_partial_caching"
28 changes: 14 additions & 14 deletions lib/easel_helpers/helpers.rb → lib/viewaide/helpers.rb
@@ -1,15 +1,15 @@
require "easel_helpers/helpers/date_helper"
require "easel_helpers/helpers/form_helper"
require "easel_helpers/helpers/link_helper"
require "easel_helpers/helpers/structure_helper"
require "easel_helpers/helpers/table_helper"
require "easel_helpers/helpers/grid_helper"
require "easel_helpers/helpers/message_helper"
require "easel_helpers/helpers/rjs_helper"
require "easel_helpers/helpers/jquery_helper"
require "easel_helpers/helpers/navigation_helper"
require "viewaide/helpers/date_helper"
require "viewaide/helpers/form_helper"
require "viewaide/helpers/link_helper"
require "viewaide/helpers/structure_helper"
require "viewaide/helpers/table_helper"
require "viewaide/helpers/grid_helper"
require "viewaide/helpers/message_helper"
require "viewaide/helpers/rjs_helper"
require "viewaide/helpers/jquery_helper"
require "viewaide/helpers/navigation_helper"

module EaselHelpers
module Viewaide
module Helpers
include DateHelper
include FormHelper
Expand All @@ -26,7 +26,7 @@ module Helpers

def other_than_grid?(classes)
(standardize_css_classes(classes).map {|s| s.to_s } -
EaselHelpers::Helpers::GridHelper::MULTIPLE_FRACTIONS).any?
Viewaide::Helpers::GridHelper::MULTIPLE_FRACTIONS).any?
end

def clean_css_classes(string_or_array, replace = {})
Expand All @@ -41,12 +41,12 @@ def clean_css_classes(string_or_array, replace = {})
end
end

fractions = css_classes & EaselHelpers::Helpers::GridHelper::MULTIPLE_FRACTIONS
fractions = css_classes & Viewaide::Helpers::GridHelper::MULTIPLE_FRACTIONS
if css_classes.any? && fractions.any?
fractions.each do |fraction|
css_classes.delete(fraction)
css_classes << self.send(fraction)
if fraction == "full" && @_easel_column_count != application_width
if fraction == "full" && @_viewaide_column_count != application_width
css_classes << last_column
end
end
Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module DateHelper

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module FormHelper

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module GridHelper
MULTIPLES = {
Expand Down Expand Up @@ -47,7 +47,7 @@ def last_column
end

def column(*args, &block)
@_easel_column_count ||= application_width
@_viewaide_column_count ||= application_width
col(*args, &block)
end

Expand Down Expand Up @@ -83,56 +83,56 @@ def clean_column(classes, &block)
end
end

def method_missing_with_easel_widths(call, *args)
def method_missing_with_viewaide_widths(call, *args)
# filter out any initial helper calls
found = false
MULTIPLE_FRACTIONS.each do |fraction|
found = true and break if call.to_s.include?(fraction)
end

method_missing_without_easel_widths(call, *args) and return unless found
method_missing_without_viewaide_widths(call, *args) and return unless found

# one of the widths is somewhere in the helper call; let's find it
call.to_s =~ /^((append|prepend|#{column_prefix})_)?(.+)$/
class_name = $2 || column_prefix
class_width = $3

if MULTIPLES.keys.include?(class_width.to_sym)
width = @_easel_column_count || application_width
width = @_viewaide_column_count || application_width
"#{class_name}-#{(width*MULTIPLES[class_width.to_sym]).to_i}"
else
method_missing_without_easel_widths(call, *args)
method_missing_without_viewaide_widths(call, *args)
end
end

alias_method_chain :method_missing, :easel_widths
alias_method_chain :method_missing, :viewaide_widths

private

def application_width; 24; end

def increase_depth(size)
@_easel_current_width ||= [application_width.to_s]
@_viewaide_current_width ||= [application_width.to_s]

if @_easel_column_count.present?
@_easel_current_width.push(@_easel_column_count.to_s)
if @_viewaide_column_count.present?
@_viewaide_current_width.push(@_viewaide_column_count.to_s)
end

@_easel_column_count = if size.to_s =~ /^\d+$/
@_viewaide_column_count = if size.to_s =~ /^\d+$/
size.to_s.to_i
else
(@_easel_column_count*MULTIPLES[size]).to_i
(@_viewaide_column_count*MULTIPLES[size]).to_i
end
end

def decrease_depth(size)
@_easel_column_count = if size.is_a?(Integer)
@_easel_current_width.last.to_i
@_viewaide_column_count = if size.is_a?(Integer)
@_viewaide_current_width.last.to_i
else
(@_easel_column_count/MULTIPLES[size]).to_i
(@_viewaide_column_count/MULTIPLES[size]).to_i
end

@_easel_current_width.pop
@_viewaide_current_width.pop
end

def col(*args, &block)
Expand All @@ -157,10 +157,10 @@ def generate_output_tag(size, *args, &block)

css_classes = [] << options.delete(:class) << args
unless options.delete(:suppress_col)
css_classes << "#{column_prefix}-#{@_easel_column_count}"
css_classes << "#{column_prefix}-#{@_viewaide_column_count}"
end

if (size.to_sym rescue nil) == :full && @_easel_column_count != application_width
if (size.to_sym rescue nil) == :full && @_viewaide_column_count != application_width
css_classes << last_column
end

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module JqueryHelper

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module LinkHelper

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module MessageHelper

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module NavigationHelper
def tab(name, path, options = {}, li_options = {})
Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module RjsHelper

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module StructureHelper

Expand Down
@@ -1,4 +1,4 @@
module EaselHelpers
module Viewaide
module Helpers
module TableHelper

Expand Down
40 changes: 40 additions & 0 deletions lib/viewaide/rails_partial_caching.rb
@@ -0,0 +1,40 @@
module ActionView
module Partials
private

def render_partial_with_viewaide(*args)
path = args.first[:partial]
locals = args.last || {}

viewaide_cached_column_counts = session[:viewaide_cached_column_counts] ||= {}

if viewaide_cached_column_counts.keys.include?(path)
@_viewaide_column_count = locals[:viewaide_width] || viewaide_cached_column_counts[path]
viewaide_cached_column_counts[path] = @_viewaide_column_count
else
if @_viewaide_column_count.is_a?(Fixnum) && path !~ /^layout/
viewaide_cached_column_counts[path] = @_viewaide_column_count
end
end

render_partial_without_viewaide(*args)
end

alias_method_chain :render_partial, :viewaide
end
end

module Viewaide
module PartialCaching
def self.included(base)
base.send :include, Viewaide::PartialCaching::InstanceMethods
base.before_filter :clear_viewaide_cache
end

module InstanceMethods
def clear_viewaide_cache
session[:viewaide_cached_column_counts] = nil unless request.xhr?
end
end
end
end
6 changes: 3 additions & 3 deletions rails/init.rb
@@ -1,4 +1,4 @@
require "easel_helpers"
require "viewaide"

ActionView::Base.send :include, EaselHelpers::Helpers
ActionController::Base.send :include, EaselHelpers::PartialCaching
ActionView::Base.send :include, Viewaide::Helpers
ActionController::Base.send :include, Viewaide::PartialCaching
4 changes: 0 additions & 4 deletions tasks/easel_helpers_tasks.rake

This file was deleted.

Empty file added tasks/viewaide_tasks.rake
Empty file.
4 changes: 2 additions & 2 deletions test/date_helper_test.rb
@@ -1,7 +1,7 @@
require 'test_helper'
require "test_helper"

class DateHelperTest < ActiveSupport::TestCase
include EaselHelpers::Helpers::DateHelper
include Viewaide::Helpers::DateHelper

context "datetime helper" do
should "default to an empty string if date is not supplied" do
Expand Down
4 changes: 2 additions & 2 deletions test/form_helper_test.rb
@@ -1,6 +1,6 @@
require 'test_helper'
require "test_helper"

class FormHelperTest < EaselHelpers::ViewTestCase
class FormHelperTest < Viewaide::ViewTestCase

context "submit_button" do

Expand Down

0 comments on commit c1dbca3

Please sign in to comment.