jakewendt-simply_photos 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (27) hide show
  1. data/README.rdoc +62 -0
  2. data/generators/simply_photos/USAGE +0 -0
  3. data/generators/simply_photos/simply_photos_generator.rb +125 -0
  4. data/generators/simply_photos/templates/autotest_simply_photos.rb +2 -0
  5. data/generators/simply_photos/templates/config/photo.yml +59 -0
  6. data/generators/simply_photos/templates/controllers/photos_controller.rb +46 -0
  7. data/generators/simply_photos/templates/functional/photos_controller_test.rb +28 -0
  8. data/generators/simply_photos/templates/images/full/missing.png +0 -0
  9. data/generators/simply_photos/templates/images/large/missing.png +0 -0
  10. data/generators/simply_photos/templates/images/medium/missing.png +0 -0
  11. data/generators/simply_photos/templates/images/original/missing.png +0 -0
  12. data/generators/simply_photos/templates/images/small/missing.png +0 -0
  13. data/generators/simply_photos/templates/javascripts/photo.js +3 -0
  14. data/generators/simply_photos/templates/migrations/add_attachments_image_to_photo.rb +15 -0
  15. data/generators/simply_photos/templates/migrations/create_photos.rb +13 -0
  16. data/generators/simply_photos/templates/models/photo.rb +15 -0
  17. data/generators/simply_photos/templates/simply_photos.rake +5 -0
  18. data/generators/simply_photos/templates/stylesheets/photo.css +7 -0
  19. data/generators/simply_photos/templates/stylesheets/photos.css +4 -0
  20. data/generators/simply_photos/templates/unit/photo_test.rb +15 -0
  21. data/generators/simply_photos/templates/views/photos/_form.html.erb +9 -0
  22. data/generators/simply_photos/templates/views/photos/_photo.html.erb +15 -0
  23. data/generators/simply_photos/templates/views/photos/edit.html.erb +12 -0
  24. data/generators/simply_photos/templates/views/photos/index.html.erb +12 -0
  25. data/generators/simply_photos/templates/views/photos/new.html.erb +11 -0
  26. data/generators/simply_photos/templates/views/photos/show.html.erb +31 -0
  27. metadata +92 -0
data/README.rdoc ADDED
@@ -0,0 +1,62 @@
1
+ = SimplyPhotos
2
+
3
+ As of version 2.0.0, this gem will be simply a generator rather than an "engine." I'll be making some "major" modifications and the road may get a bit bumpy.
4
+
5
+
6
+ == ToDo
7
+
8
+ * Add attachment tests
9
+
10
+
11
+ == Required Gem Sources
12
+
13
+ gem sources -a http://rubygems.org
14
+ gem sources -a http://gems.github.com
15
+
16
+ == Required Gems
17
+
18
+ * {jakewendt-ruby_extension}[http://github.com/jakewendt/ruby_extension] - modifications, updates and patches for ruby.
19
+ * rails ~> 2
20
+ * ssl_requirement
21
+ * ryanb-acts-as-list
22
+ * RedCloth
23
+ * paperclip
24
+ * thoughtbot-factory_girl
25
+ * {jakewendt-simply_helpful}[http://github.com/jakewendt/simply_helpful]
26
+ * {jakewendt-calnet_authenticated}[http://github.com/jakewendt/calnet_authenticated]
27
+ * {jakewendt-simply_authorized}[http://github.com/jakewendt/simply_authorized]
28
+
29
+ == Installation (as a plugin/engine)
30
+
31
+ cp config/s3.yml.example config/s3.yml
32
+ # Add your own s3 access keys. Leave 'test' as it is.
33
+
34
+ # No longer needed as the components are just installed in the app.
35
+ # config.gem 'jakewendt-simply_photos',
36
+ # :source => 'http://rubygems.org'
37
+
38
+ script/generate simply_photos
39
+
40
+ == Testing (as an app)
41
+
42
+ rake db:migrate
43
+ rake db:fixtures:load
44
+ rake test
45
+ script/server
46
+
47
+ == Gemified with Jeweler
48
+
49
+ vi Rakefile
50
+ rake version:write
51
+
52
+ rake version:bump:patch
53
+ rake version:bump:minor
54
+ rake version:bump:major
55
+
56
+ rake gemspec
57
+
58
+ rake install
59
+ rake release
60
+
61
+
62
+ Copyright (c) 2010 [Jake Wendt], released under the MIT license
File without changes
@@ -0,0 +1,125 @@
1
+ class SimplyPhotosGenerator < Rails::Generator::Base
2
+
3
+ def manifest
4
+ # See Rails::Generator::Commands::Create
5
+ # rails-2.3.10/lib/rails_generator/commands.rb
6
+ # for code methods for record (Manifest)
7
+ record do |m|
8
+
9
+ # multiple runs will add this route multiple times.
10
+ # How to do this conditionally?
11
+ m.route_resources :photos
12
+
13
+ # m.directory('config/autotest')
14
+ # m.file('autotest_simply_photos.rb', 'config/autotest/simply_photos.rb')
15
+ # m.directory('lib/tasks')
16
+ # m.file('simply_photos.rake', 'lib/tasks/simply_photos.rake')
17
+
18
+ # File.open('Rakefile','a'){|f|
19
+ # f.puts <<-EOF
20
+ ## From `script/generate simply_photos` ...
21
+ #require 'simply_photos/test_tasks'
22
+ # EOF
23
+ # }
24
+ #
25
+ # File.open('.autotest','a'){|f|
26
+ # f.puts <<-EOF
27
+ ## From `script/generate simply_photos` ...
28
+ #require 'simply_photos/autotest'
29
+ # EOF
30
+ # }
31
+
32
+ %w( create_photos add_attachments_image_to_photo
33
+ ).each do |migration|
34
+ m.migration_template "migrations/#{migration}.rb",
35
+ 'db/migrate', :migration_file_name => migration
36
+ end
37
+
38
+ dot = File.dirname(__FILE__)
39
+ m.directory('config')
40
+ Dir["#{dot}/templates/config/*yml"].each{|file|
41
+ f = file.split('/').slice(-2,2).join('/')
42
+ m.file(f, "config/#{File.basename(file)}")
43
+ }
44
+
45
+ m.directory('public/javascripts')
46
+ Dir["#{dot}/templates/javascripts/*js"].each{|file|
47
+ f = file.split('/').slice(-2,2).join('/')
48
+ m.file(f, "public/javascripts/#{File.basename(file)}")
49
+ }
50
+
51
+ m.directory('public/stylesheets')
52
+ Dir["#{dot}/templates/stylesheets/*css"].each{|file|
53
+ f = file.split('/').slice(-2,2).join('/')
54
+ m.file(f, "public/stylesheets/#{File.basename(file)}")
55
+ }
56
+
57
+ m.directory('public/images')
58
+ %w( full large medium original small ).each do |style|
59
+ m.directory("public/images/#{style}")
60
+ m.file("images/#{style}/missing.png",
61
+ "public/images/#{style}/missing.png")
62
+ end
63
+
64
+ m.directory('app/models')
65
+ Dir["#{dot}/templates/models/*rb"].each{|file|
66
+ f = file.split('/').slice(-2,2).join('/')
67
+ m.file(f, "app/models/#{File.basename(file)}")
68
+ }
69
+
70
+ m.directory('app/controllers ')
71
+ Dir["#{dot}/templates/controllers/*rb"].each{|file|
72
+ f = file.split('/').slice(-2,2).join('/')
73
+ m.file(f, "app/controllers/#{File.basename(file)}")
74
+ }
75
+
76
+ m.directory('app/views/photos')
77
+ Dir["#{dot}/templates/views/photos/*rb"].each{|file|
78
+ f = file.split('/').slice(-3,3).join('/') # has an extra directory in path
79
+ m.file(f, "app/views/photos/#{File.basename(file)}")
80
+ }
81
+
82
+ m.directory('test/functional')
83
+ Dir["#{dot}/templates/functional/*rb"].each{|file|
84
+ f = file.split('/').slice(-2,2).join('/')
85
+ m.file(f, "test/functional/#{File.basename(file)}")
86
+ }
87
+
88
+ m.directory('test/unit')
89
+ Dir["#{dot}/templates/unit/*rb"].each{|file|
90
+ f = file.split('/').slice(-2,2).join('/')
91
+ m.file(f, "test/unit/#{File.basename(file)}")
92
+ }
93
+ end
94
+ end
95
+
96
+ end
97
+ module Rails::Generator::Commands
98
+ class Create
99
+ def migration_template(relative_source,
100
+ relative_destination, template_options = {})
101
+ migration_directory relative_destination
102
+ migration_file_name = template_options[
103
+ :migration_file_name] || file_name
104
+ if migration_exists?(migration_file_name)
105
+ puts "Another migration is already named #{migration_file_name}: #{existing_migrations(migration_file_name).first}: Skipping"
106
+ else
107
+ template(relative_source, "#{relative_destination}/#{next_migration_string}_#{migration_file_name}.rb", template_options)
108
+ end
109
+ end
110
+ end # Create
111
+ class Base
112
+ protected
113
+ # the loop through migrations happens so fast
114
+ # that they all have the same timestamp which
115
+ # won't work when you actually try to migrate.
116
+ # All the timestamps MUST be unique.
117
+ def next_migration_string(padding = 3)
118
+ @s = (!@s.nil?)? @s.to_i + 1 : if ActiveRecord::Base.timestamped_migrations
119
+ Time.now.utc.strftime("%Y%m%d%H%M%S")
120
+ else
121
+ "%.#{padding}d" % next_migration_number
122
+ end
123
+ end
124
+ end # Base
125
+ end
@@ -0,0 +1,2 @@
1
+ # From `script/generate simply_photos` ...
2
+ require 'simply_photos/autotest'
@@ -0,0 +1,59 @@
1
+ DEFAULTS: &DEFAULTS
2
+ :styles:
3
+ :full: '900>'
4
+ :large: '800>'
5
+ :medium: '600>'
6
+ :small: '150x50>'
7
+
8
+ # > means DO NOT enlarge, only shrink
9
+
10
+ # :attachment is the attachment name NOT the model name
11
+ # for document they are the same, but not photos
12
+
13
+ # why /system/ ???
14
+ <%# common = "/system/:attachment/:id/:style/:filename" %>
15
+ <% common = "photos/:id/:style/:filename" %>
16
+
17
+
18
+ #>> Rails.root.to_s.split('/')
19
+ #=> ["", "var", "lib", "tomcat5", "webapps", "clic", "WEB-INF"]
20
+
21
+ #>> Rails.root.to_s.split('/')
22
+ #=> ["", "Users", "jakewendt", "github_repo", "jakewendt", "ucb_ccls_clic"]
23
+
24
+ <%
25
+ app_name = ( defined?(RAILS_APP_NAME) ) ?
26
+ RAILS_APP_NAME :
27
+ Rails.root.to_s.split('/').reject{|x|x == "WEB-INF"}.last
28
+ %>
29
+
30
+
31
+ development:
32
+ :url: <%= "/development/#{common}" %>
33
+ :path: <%= "#{Rails.root}/public/development/#{common}" %>
34
+ <<: *DEFAULTS
35
+
36
+ test:
37
+ :url: <%= "/test/#{common}" %>
38
+ :path: <%= "#{Rails.root}/public/test/#{common}" %>
39
+ <<: *DEFAULTS
40
+
41
+ production:
42
+ # Set the storage class to RRS which is cheaper than
43
+ # the default of STANDARD
44
+ :s3_headers:
45
+ x-amz-storage-class: REDUCED_REDUNDANCY
46
+ # public_read or private
47
+ :s3_permissions: :public_read
48
+ :storage: :s3
49
+ :s3_protocol: https
50
+ :s3_credentials: <%="#{Rails.root}/config/s3.yml" %>
51
+ :bucket: <%= app_name %>
52
+ # common has a : as the first char so it needs special care
53
+ # or the string will magically be turned into a symbol
54
+ # which isn't what we want <%#= "\"#{common}\"" %>
55
+ # Not anymore.
56
+ :path: <%= common %>
57
+ # S3 must have a defined path or will generate
58
+ # "Stack level too deep" errors
59
+ <<: *DEFAULTS
@@ -0,0 +1,46 @@
1
+ class PhotosController < ApplicationController
2
+
3
+ before_filter :may_maintain_pages_required
4
+ before_filter :id_required, :only => [ :show, :edit, :update, :destroy ]
5
+
6
+ def index
7
+ @photos = Photo.all
8
+ end
9
+
10
+ def new
11
+ @photo = Photo.new
12
+ end
13
+
14
+ def create
15
+ @photo = Photo.new(params[:photo])
16
+ @photo.save!
17
+ redirect_to @photo
18
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
19
+ flash.now[:error] = "Error"
20
+ render :action => 'new'
21
+ end
22
+
23
+ def update
24
+ @photo.update_attributes!(params[:photo])
25
+ redirect_to @photo
26
+ rescue ActiveRecord::RecordInvalid, ActiveRecord::RecordNotSaved
27
+ flash.now[:error] = "Error"
28
+ render :action => 'edit'
29
+ end
30
+
31
+ def destroy
32
+ @photo.destroy
33
+ redirect_to photos_path
34
+ end
35
+
36
+ protected
37
+
38
+ def id_required
39
+ if !params[:id].blank? and Photo.exists?(params[:id])
40
+ @photo = Photo.find(params[:id])
41
+ else
42
+ access_denied("Valid photo id required!", photos_path)
43
+ end
44
+ end
45
+
46
+ end
@@ -0,0 +1,28 @@
1
+ require 'test_helper'
2
+
3
+ class PhotosControllerTest < ActionController::TestCase
4
+
5
+ ASSERT_ACCESS_OPTIONS = {
6
+ :model => 'Photo',
7
+ :actions => [:new,:create,:edit,:update,:destroy,:show,:index],
8
+ :method_for_create => :factory_create,
9
+ :attributes_for_create => :factory_attributes
10
+ }
11
+
12
+ def factory_create(options={})
13
+ Factory(:photo,options)
14
+ end
15
+ def factory_attributes(options={})
16
+ Factory.attributes_for(:photo,options)
17
+ end
18
+
19
+ assert_access_with_https
20
+ assert_access_with_login({
21
+ :logins => [:superuser,:administrator,:editor]})
22
+
23
+ assert_no_access_with_http
24
+ assert_no_access_with_login({
25
+ :logins => [:interviewer,:reader,:active_user] })
26
+ assert_no_access_without_login
27
+
28
+ end
@@ -0,0 +1,3 @@
1
+ jQuery(function(){
2
+ jQuery('#images').tabs();
3
+ });
@@ -0,0 +1,15 @@
1
+ class AddAttachmentsImageToPhoto < ActiveRecord::Migration
2
+ def self.up
3
+ add_column :photos, :image_file_name, :string
4
+ add_column :photos, :image_content_type, :string
5
+ add_column :photos, :image_file_size, :integer
6
+ add_column :photos, :image_updated_at, :datetime
7
+ end
8
+
9
+ def self.down
10
+ remove_column :photos, :image_file_name
11
+ remove_column :photos, :image_content_type
12
+ remove_column :photos, :image_file_size
13
+ remove_column :photos, :image_updated_at
14
+ end
15
+ end
@@ -0,0 +1,13 @@
1
+ class CreatePhotos < ActiveRecord::Migration
2
+ def self.up
3
+ create_table :photos do |t|
4
+ t.string :title, :null => false
5
+ t.text :caption
6
+ t.timestamps
7
+ end
8
+ end
9
+
10
+ def self.down
11
+ drop_table :photos
12
+ end
13
+ end
@@ -0,0 +1,15 @@
1
+ class Photo < ActiveRecord::Base
2
+
3
+ validates_presence_of :title
4
+ validates_length_of :title, :minimum => 4
5
+
6
+ has_attached_file :image,
7
+ YAML::load(ERB.new(IO.read(File.expand_path(
8
+ File.join(File.dirname(__FILE__),'../..','config/photo.yml')
9
+ ))).result)[Rails.env]
10
+
11
+ def to_s
12
+ title
13
+ end
14
+
15
+ end
@@ -0,0 +1,5 @@
1
+ # From `script/generate simply_photos` ...
2
+ unless Gem.source_index.find_name('jakewendt-simply_photos').empty?
3
+ gem 'jakewendt-simply_photos'
4
+ require 'simply_photos/test_tasks'
5
+ end
@@ -0,0 +1,7 @@
1
+ #images ul.ui-tabs-nav {
2
+ /*
3
+ without this, the tabs background is too huge
4
+ with this, the tabs background is a bit too small
5
+ */
6
+ display:inline-block;
7
+ }
@@ -0,0 +1,4 @@
1
+ form.new_photo,
2
+ form.edit_photo {
3
+ display:inline-block;
4
+ }
@@ -0,0 +1,15 @@
1
+ require 'test_helper'
2
+
3
+ class PhotoTest < ActiveSupport::TestCase
4
+
5
+ assert_should_require(:title)
6
+
7
+ test "should create photo" do
8
+ assert_difference 'Photo.count' do
9
+ object = create_object
10
+ assert !object.new_record?,
11
+ "#{object.errors.full_messages.to_sentence}"
12
+ end
13
+ end
14
+
15
+ end
@@ -0,0 +1,9 @@
1
+ <% stylesheets('photos') %>
2
+ <%= f.wrapped_text_field :title %>
3
+ <%= f.wrapped_file_field :image %>
4
+ <% if @photo.image? %>
5
+ <div class='image_preview'>
6
+ <%= image_tag(@photo.image.url(:full))%>
7
+ </div>
8
+ <% end %>
9
+ <%= f.wrapped_text_area :caption %>
@@ -0,0 +1,15 @@
1
+ <% content_tag_for( :tr, photo, :class => 'row' ) do %>
2
+ <td class='thumb'>
3
+ <%= image_tag(photo.image.url(:small)) %>
4
+ </td>
5
+ <td class='title'>
6
+ <%= link_to photo.title, photo %>
7
+ </td>
8
+ <td class='manage'>
9
+ <%= button_link_to 'Edit', edit_photo_path(photo) %>&nbsp;
10
+ <% destroy_link_to 'Destroy', photo_path(photo) do %>
11
+ <%= hidden_field_tag 'confirm', "Destroy photo '#{photo}'?",
12
+ :id => nil %>
13
+ <% end %>
14
+ </td>
15
+ <% end %><!-- class='photo row' -->
@@ -0,0 +1,12 @@
1
+ <h2>Editing Photo</h2>
2
+
3
+ <% form_for(@photo,
4
+ :html => { :multipart => true }) do |f| %>
5
+ <%= f.error_messages %>
6
+ <%= render 'form',:f => f %>
7
+ <p>
8
+ <%= f.submit( "Update this Photo" )%>&nbsp;
9
+ <%= button_link_to 'Show this Photo', @photo %>&nbsp;
10
+ <%= button_link_to 'Back to Photos', photos_path %>
11
+ </p>
12
+ <% end %>
@@ -0,0 +1,12 @@
1
+ <% javascripts('simply_helpful') %>
2
+ <% stylesheets('photos') %>
3
+ <h2>Photos</h2>
4
+ <% if @photos.length > 0 %>
5
+ <table id='photos'><tbody>
6
+ <%= render :partial => 'photo', :collection => @photos %>
7
+ </tbody></table><!-- id='photos' -->
8
+ <% else %>
9
+ Sorry, but no photos yet.
10
+ <% end %>
11
+
12
+ <p><%= button_link_to 'Create New Photo', new_photo_path %></p>
@@ -0,0 +1,11 @@
1
+ <h2>New Photo</h2>
2
+
3
+ <% form_for(@photo,
4
+ :html => { :multipart => true }) do |f| %>
5
+ <%= f.error_messages %>
6
+ <%= render 'form', :f => f %>
7
+ <p>
8
+ <%= f.submit( "Create Photo" )%>&nbsp;
9
+ <%= button_link_to "Cancel", photos_path %>
10
+ </p>
11
+ <% end %>
@@ -0,0 +1,31 @@
1
+ <% javascripts('photo') %>
2
+ <% stylesheets('photo','base/jquery.ui.all.css') %>
3
+
4
+ <p>
5
+ <b>Title:</b>
6
+ <%=h @photo.title %>
7
+ </p>
8
+
9
+ <div id='images'>
10
+ <ul>
11
+ <% @photo.image.styles.keys.unshift(:original).each do |key| %>
12
+ <li><%= link_to key, "##{key}" %></li>
13
+ <% end %>
14
+ </ul>
15
+ <% @photo.image.styles.keys.unshift(:original).each do |key| %>
16
+ <div id="<%= key %>" class='image_preview'>
17
+ <p><%= link_to( @photo.image.url(key), @photo.image.url(key) ) %></p>
18
+ <%= image_tag @photo.image.url(key) %>
19
+ </div><!-- class='image_preview' -->
20
+ <% end %>
21
+ </div><!-- id='images' -->
22
+
23
+
24
+
25
+ <p>
26
+ <b>Caption:</b>
27
+ <%=h @photo.caption %>
28
+ </p>
29
+
30
+ <%= button_link_to 'Edit this Photo', edit_photo_path(@photo) %>&nbsp;
31
+ <%= button_link_to 'Back to Photos', photos_path %>
metadata ADDED
@@ -0,0 +1,92 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jakewendt-simply_photos
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 2
8
+ - 0
9
+ - 0
10
+ version: 2.0.0
11
+ platform: ruby
12
+ authors:
13
+ - George 'Jake' Wendt
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-09-30 00:00:00 -07:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: longer description of your gem
23
+ email: github@jake.otherinbox.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.rdoc
30
+ files:
31
+ - generators/simply_photos/USAGE
32
+ - generators/simply_photos/simply_photos_generator.rb
33
+ - generators/simply_photos/templates/autotest_simply_photos.rb
34
+ - generators/simply_photos/templates/config/photo.yml
35
+ - generators/simply_photos/templates/controllers/photos_controller.rb
36
+ - generators/simply_photos/templates/functional/photos_controller_test.rb
37
+ - generators/simply_photos/templates/images/full/missing.png
38
+ - generators/simply_photos/templates/images/large/missing.png
39
+ - generators/simply_photos/templates/images/medium/missing.png
40
+ - generators/simply_photos/templates/images/original/missing.png
41
+ - generators/simply_photos/templates/images/small/missing.png
42
+ - generators/simply_photos/templates/javascripts/photo.js
43
+ - generators/simply_photos/templates/migrations/add_attachments_image_to_photo.rb
44
+ - generators/simply_photos/templates/migrations/create_photos.rb
45
+ - generators/simply_photos/templates/models/photo.rb
46
+ - generators/simply_photos/templates/simply_photos.rake
47
+ - generators/simply_photos/templates/stylesheets/photo.css
48
+ - generators/simply_photos/templates/stylesheets/photos.css
49
+ - generators/simply_photos/templates/unit/photo_test.rb
50
+ - generators/simply_photos/templates/views/photos/_form.html.erb
51
+ - generators/simply_photos/templates/views/photos/_photo.html.erb
52
+ - generators/simply_photos/templates/views/photos/edit.html.erb
53
+ - generators/simply_photos/templates/views/photos/index.html.erb
54
+ - generators/simply_photos/templates/views/photos/new.html.erb
55
+ - generators/simply_photos/templates/views/photos/show.html.erb
56
+ - README.rdoc
57
+ has_rdoc: true
58
+ homepage: http://github.com/jakewendt/simply_photos
59
+ licenses: []
60
+
61
+ post_install_message:
62
+ rdoc_options: []
63
+
64
+ require_paths:
65
+ - lib
66
+ required_ruby_version: !ruby/object:Gem::Requirement
67
+ none: false
68
+ requirements:
69
+ - - ">="
70
+ - !ruby/object:Gem::Version
71
+ hash: 3
72
+ segments:
73
+ - 0
74
+ version: "0"
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ none: false
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ hash: 3
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.6.2
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: one-line summary of your gem
91
+ test_files: []
92
+