Permalink
Browse files

added image_table builder.

  • Loading branch information...
1 parent fbadf06 commit 4147fd43d00685afdcc62c5ed3f85e71ad75e7c2 @amoslanka amoslanka committed May 27, 2011
View
1 .rvmrc
@@ -0,0 +1 @@
+rvm use 1.9.2-head@activeadmin --create
View
7 Gemfile
@@ -1,10 +1,7 @@
source "http://rubygems.org"
-# Add dependencies required to use your gem here.
-# Example:
-# gem "activesupport", ">= 2.3.5"
-# Add dependencies to develop your gem here.
-# Include everything needed to run rake, tests, features, etc.
+gem 'activeadmin'
+
group :development do
gem "shoulda", ">= 0"
gem "bundler", "~> 1.0.0"
View
118 Gemfile.lock
@@ -0,0 +1,118 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ abstract (1.0.0)
+ actionmailer (3.0.7)
+ actionpack (= 3.0.7)
+ mail (~> 2.2.15)
+ actionpack (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ builder (~> 2.1.2)
+ erubis (~> 2.6.6)
+ i18n (~> 0.5.0)
+ rack (~> 1.2.1)
+ rack-mount (~> 0.6.14)
+ rack-test (~> 0.5.7)
+ tzinfo (~> 0.3.23)
+ activeadmin (0.2.1)
+ devise (>= 1.1.2)
+ formtastic (>= 1.1.0)
+ haml (>= 3.0.18)
+ inherited_views
+ meta_search (>= 0.9.2)
+ rails (>= 3.0.0)
+ will_paginate (>= 3.0.pre2)
+ activemodel (3.0.7)
+ activesupport (= 3.0.7)
+ builder (~> 2.1.2)
+ i18n (~> 0.5.0)
+ activerecord (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ arel (~> 2.0.2)
+ tzinfo (~> 0.3.23)
+ activeresource (3.0.7)
+ activemodel (= 3.0.7)
+ activesupport (= 3.0.7)
+ activesupport (3.0.7)
+ arel (2.0.10)
+ bcrypt-ruby (2.1.4)
+ builder (2.1.2)
+ devise (1.3.4)
+ bcrypt-ruby (~> 2.1.2)
+ orm_adapter (~> 0.0.3)
+ warden (~> 1.0.3)
+ erubis (2.6.6)
+ abstract (>= 1.0.0)
+ formtastic (1.2.3)
+ actionpack (>= 2.3.7)
+ activesupport (>= 2.3.7)
+ i18n (~> 0.4)
+ git (1.2.5)
+ haml (3.1.1)
+ has_scope (0.5.0)
+ i18n (0.5.0)
+ inherited_resources (1.2.2)
+ has_scope (~> 0.5.0)
+ responders (~> 0.6.0)
+ inherited_views (0.0.2)
+ formtastic (>= 0.9.8)
+ inherited_resources (>= 1.0.6)
+ will_paginate (>= 2.3.12)
+ jeweler (1.6.0)
+ bundler (~> 1.0.0)
+ git (>= 1.2.5)
+ rake
+ mail (2.2.19)
+ activesupport (>= 2.3.6)
+ i18n (>= 0.4.0)
+ mime-types (~> 1.16)
+ treetop (~> 1.4.8)
+ meta_search (1.0.5)
+ actionpack (~> 3.0.2)
+ activerecord (~> 3.0.2)
+ activesupport (~> 3.0.2)
+ arel (~> 2.0.2)
+ mime-types (1.16)
+ orm_adapter (0.0.5)
+ polyglot (0.3.1)
+ rack (1.2.3)
+ rack-mount (0.6.14)
+ rack (>= 1.0.0)
+ rack-test (0.5.7)
+ rack (>= 1.0)
+ rails (3.0.7)
+ actionmailer (= 3.0.7)
+ actionpack (= 3.0.7)
+ activerecord (= 3.0.7)
+ activeresource (= 3.0.7)
+ activesupport (= 3.0.7)
+ bundler (~> 1.0)
+ railties (= 3.0.7)
+ railties (3.0.7)
+ actionpack (= 3.0.7)
+ activesupport (= 3.0.7)
+ rake (>= 0.8.7)
+ thor (~> 0.14.4)
+ rake (0.9.0)
+ rcov (0.9.9)
+ responders (0.6.4)
+ shoulda (2.11.3)
+ thor (0.14.6)
+ treetop (1.4.9)
+ polyglot (>= 0.3.1)
+ tzinfo (0.3.27)
+ warden (1.0.4)
+ rack (>= 1.0)
+ will_paginate (3.0.pre2)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ activeadmin
+ bundler (~> 1.0.0)
+ jeweler (~> 1.6.0)
+ rcov
+ shoulda
View
4 Rakefile
@@ -17,8 +17,8 @@ Jeweler::Tasks.new do |gem|
gem.name = "activeadmin-paperclip"
gem.homepage = "http://github.com/amoslanka/activeadmin-paperclip"
gem.license = "MIT"
- gem.summary = %Q{TODO: one-line summary of your gem}
- gem.description = %Q{TODO: longer description of your gem}
+ gem.summary = %Q{Adds Paperclip support to ActiveAdmin}
+ gem.description = %Q{Adds Paperclip support to ActiveAdmin}
gem.email = "amoslanka@gmail.com"
gem.authors = ["Amos Lanka"]
# dependencies defined in Gemfile
View
59 activeadmin-paperclip.gemspec
@@ -0,0 +1,59 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE DIRECTLY
+# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
+# -*- encoding: utf-8 -*-
+
+Gem::Specification.new do |s|
+ s.name = %q{activeadmin-paperclip}
+ s.version = "0.1.0"
+
+ s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
+ s.authors = ["Amos Lanka"]
+ s.date = %q{2011-05-25}
+ s.description = %q{Adds Paperclip support to ActiveAdmin}
+ s.email = %q{amoslanka@gmail.com}
+ s.extra_rdoc_files = [
+ "LICENSE.txt",
+ "README.rdoc"
+ ]
+ s.files = [
+ ".document",
+ "Gemfile",
+ "LICENSE.txt",
+ "README.rdoc",
+ "Rakefile",
+ "VERSION",
+ "lib/activeadmin-paperclip.rb",
+ "test/helper.rb"
+ ]
+ s.homepage = %q{http://github.com/amoslanka/activeadmin-paperclip}
+ s.licenses = ["MIT"]
+ s.require_paths = ["lib"]
+ s.rubygems_version = %q{1.5.0}
+ s.summary = %q{Adds Paperclip support to ActiveAdmin}
+
+ if s.respond_to? :specification_version then
+ s.specification_version = 3
+
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
+ s.add_runtime_dependency(%q<activeadmin>, [">= 0"])
+ s.add_development_dependency(%q<shoulda>, [">= 0"])
+ s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_development_dependency(%q<jeweler>, ["~> 1.6.0"])
+ s.add_development_dependency(%q<rcov>, [">= 0"])
+ else
+ s.add_dependency(%q<activeadmin>, [">= 0"])
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
+ s.add_dependency(%q<rcov>, [">= 0"])
+ end
+ else
+ s.add_dependency(%q<activeadmin>, [">= 0"])
+ s.add_dependency(%q<shoulda>, [">= 0"])
+ s.add_dependency(%q<bundler>, ["~> 1.0.0"])
+ s.add_dependency(%q<jeweler>, ["~> 1.6.0"])
+ s.add_dependency(%q<rcov>, [">= 0"])
+ end
+end
+
View
9 lib/activeadmin-paperclip.rb
@@ -0,0 +1,9 @@
+require 'activeadmin'
+
+module ActiveAdmin
+ module Paperclip
+
+ require 'activeadmin-paperclip/views'
+
+ end
+end
View
10 lib/activeadmin-paperclip/views.rb
@@ -0,0 +1,10 @@
+module ActiveAdmin
+ module Paperclip
+ module Views
+
+ # Loads all the classes in views/*.rb
+ Dir[File.expand_path('../views', __FILE__) + "/**/*.rb"].sort.each{ |f| require f }
+
+ end
+ end
+end
View
45 lib/activeadmin-paperclip/views/attachment_panel.rb
@@ -0,0 +1,45 @@
+module ActiveAdmin
+ module Views
+
+ # Attachment Panel provides a panel that outputs all styles for
+ # the provided paperclip attachment. Typically should be used on
+ # the view action.
+ #
+ class AttachmentPanelFor < ActiveAdmin::Views::Panel
+ builder_method :attachment_panel_for
+
+ # Pass in resource in order to create a table for a resource
+ # other than the current.
+ # Provide attachment_name as a symbol of the name of the paperclip
+ # property. Typically, :image or :attachment
+ # Attributes:
+ # Inherits attribute options from ActiveAdmin::Views::Panel, and
+ # includes :title
+
+ def build(resource, attachment_name, attributes={})
+ @resource = resource
+ @attachment_name = attachment_name
+ title = attributes.delete(:title) || attachment_name.to_s
+ add_class "paperclip"
+ super title, attributes
+
+ attachment = (@resource.respond_to? @attachment_name.to_sym) ? @resource.send(@attachment_name.to_sym) : nil
+ image_table_for attachment, attributes
+ end
+
+ end
+
+ # Creates an attachment panel for the current resource.
+ class AttachmentPanel < AttachmentPanelFor
+ builder_method :attachment_panel
+
+ def build(attachment_name, attributes = {})
+ super resource, attachment_name, attributes
+ end
+ end
+
+
+
+ end
+end
+
View
62 lib/activeadmin-paperclip/views/image_sidebar.rb
@@ -0,0 +1,62 @@
+# module ActiveAdmin
+# module Views
+# class ImageSidebar < ImageTable
+# builder_method :image_sidebar
+#
+# # def build(attachment, *styles)
+# # @attachment = attachment
+# # @style_list = attachment.styles.collect do |style| style.first end
+# # add_class "paperclip"
+# # add_class "attributes_table"
+# # styles = collect_styles(*styles)
+# # super @attachment.instance, *styles
+# # end
+# #
+# # # Collects and organizes the list of styles to display. If :except or :only are
+# # # provided, these modify the list that is displayed. If no styles are provided,
+# # # all are displayed.
+# # def collect_styles(*styles)
+# # @options = {}
+# # styles.each do |style|
+# # @options.update(styles.delete(style)) if style.is_a?(Hash)
+# # end
+# #
+# # # If no styles provided, we adapt all styles.
+# # styles = styles.empty? ? @style_list.clone : styles
+# #
+# # # except = styles.delete(:except)
+# # except = @options[:except]
+# # except = [except] if (except && !except.is_a?(Enumerable))
+# # except.collect! do |item| item.is_a?(String) ? item.to_sym : item end if !except.nil?
+# # # only = styles.delete(:only)
+# # only = @options[:only]
+# # only = [only] if (!only.nil? && !only.is_a?(Enumerable))
+# # only.collect! do |item| item.is_a?(String) ? item.to_sym : item end if !only.nil?
+# #
+# # # Only defaults to all styles if not defined.
+# # if !only.nil? then
+# # # Remove styles to display if not in only group
+# # styles.delete_if do |item| !only.include?(item) end
+# # end
+# # # Remove excepted styles
+# # if !except.nil? then
+# # styles.delete_if do |item| except.include?(item) end
+# # end
+# #
+# # styles
+# # end
+# #
+# # # Overrides the content_for_attribute and returns the content
+# # # from the list of styles for the image attachment
+# # def content_for_attribute(attr)
+# # if @style_list.include?(attr)
+# # image_tag @attachment.url(attr), :style => "max-width:100%", :class => "style-#{attr.to_s}"
+# # else
+# # super(attr)
+# # end
+# # end
+#
+#
+# end
+# end
+# end
View
77 lib/activeadmin-paperclip/views/image_table.rb
@@ -0,0 +1,77 @@
+module ActiveAdmin
+ module Views
+ class ImageTableFor < AttributesTable
+ builder_method :image_table_for
+
+ def build(record, attachment_name, *styles)
+
+ raise "Record cannot be nil." if record.nil?
+ @attachment = attachment = (record.respond_to? attachment_name.to_sym) ? record.send(attachment_name.to_sym) : nil
+
+ @style_list = !@attachment.nil? ? @attachment.styles.collect do |style| style.first end : []
+ add_class "paperclip"
+ add_class "attributes_table"
+ styles = collect_styles(*styles)
+ super record, *styles
+
+ end
+
+ # Collects and organizes the list of styles to display. If :except or :only are
+ # provided, these modify the list that is displayed. If no styles are provided,
+ # all are displayed.
+ def collect_styles(*styles)
+ @options = {}
+ styles.each do |style|
+ @options.update(styles.delete(style)) if style.is_a?(Hash)
+ end
+
+ # If no styles provided, we adapt all styles.
+ styles = styles.empty? ? @style_list.clone : styles
+
+ # except = styles.delete(:except)
+ except = @options[:except]
+ except = [except] if (except && !except.is_a?(Enumerable))
+ except.collect! do |item| item.is_a?(String) ? item.to_sym : item end if !except.nil?
+ # only = styles.delete(:only)
+ only = @options[:only]
+ only = [only] if (!only.nil? && !only.is_a?(Enumerable))
+ only.collect! do |item| item.is_a?(String) ? item.to_sym : item end if !only.nil?
+
+ # Only defaults to all styles if not defined.
+ if !only.nil? then
+ # Remove styles to display if not in only group
+ styles.delete_if do |item| !only.include?(item) end
+ end
+ # Remove excepted styles
+ if !except.nil? then
+ styles.delete_if do |item| except.include?(item) end
+ end
+
+ styles
+ end
+
+ # Overrides the content_for_attribute and returns the content
+ # from the list of styles for the image attachment
+ def content_for_attribute(attr)
+
+ if @style_list.include?(attr)
+ src = @attachment.url(attr)
+ image_tag src, :style => "max-width:100%", :class => "style-#{attr.to_s}" if @attachment.file?
+ elsif @record.respond_to?(attr.to_sym)
+ super(attr)
+ end
+
+ end
+
+
+ end
+
+ # class ImageTable < ImageTableFor
+ # builder_method :image_table
+ # def build(attachment_name, *styles)
+ # super resource.send(attachment_name.to_sym), *styles
+ # end
+ # end
+
+ end
+end
View
2 test/test_activeadmin-paperclip.rb → test/test_activeadmin_paperclip.rb
@@ -1,6 +1,6 @@
require 'helper'
-class TestActiveadminPaperclip < Test::Unit::TestCase
+class TestActiveAdminPaperclip < Test::Unit::TestCase
should "probably rename this file and start testing for real" do
flunk "hey buddy, you should probably rename this file and start testing for real"
end

0 comments on commit 4147fd4

Please sign in to comment.