tkh_illustrations 0.0.10 → 0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/CHANGELOG.md +5 -0
- data/README.md +9 -5
- data/app/controllers/headers_controller.rb +49 -0
- data/app/models/header.rb +21 -0
- data/app/uploaders/photo_uploader.rb +68 -0
- data/app/views/headers/_form.html.erb +13 -0
- data/app/views/headers/edit.html.erb +2 -0
- data/app/views/headers/index.html.erb +32 -0
- data/app/views/headers/new.html.erb +2 -0
- data/app/views/headers/show.html.erb +16 -0
- data/config/routes.rb +1 -0
- data/lib/generators/tkh_illustrations/create_or_update_locales/templates/de.yml +3 -0
- data/lib/generators/tkh_illustrations/create_or_update_locales/templates/en.yml +7 -4
- data/lib/generators/tkh_illustrations/create_or_update_locales/templates/es.yml +7 -4
- data/lib/generators/tkh_illustrations/create_or_update_locales/templates/fr.yml +3 -0
- data/lib/generators/tkh_illustrations/create_or_update_migrations/create_or_update_migrations_generator.rb +2 -0
- data/lib/generators/tkh_illustrations/create_or_update_migrations/templates/create_headers.rb +15 -0
- data/lib/tasks/tkh_illustrations_tasks.rake +6 -0
- data/lib/tkh_illustrations/version.rb +1 -1
- metadata +13 -4
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -29,11 +29,11 @@ And then execute:
|
|
29
29
|
|
30
30
|
$ bundle
|
31
31
|
|
32
|
-
Import
|
32
|
+
Import migrations
|
33
33
|
|
34
34
|
$ rake tkh_illustrations:install
|
35
35
|
|
36
|
-
Run the
|
36
|
+
Run the migrations
|
37
37
|
|
38
38
|
$ rake db:migrate
|
39
39
|
|
@@ -44,9 +44,9 @@ And then of course restart your server!
|
|
44
44
|
|
45
45
|
## Upgrading
|
46
46
|
|
47
|
-
If you are upgrading and think you might need to upgrade your migrations or your locale files, run
|
47
|
+
If you are upgrading and think you might need to upgrade your migrations or your locale files, run:
|
48
48
|
|
49
|
-
$ rake tkh_illustrations:
|
49
|
+
$ rake tkh_illustrations:update
|
50
50
|
|
51
51
|
and
|
52
52
|
|
@@ -56,10 +56,14 @@ and
|
|
56
56
|
|
57
57
|
## Usage
|
58
58
|
|
59
|
-
The section is located at:
|
59
|
+
The main section is located at:
|
60
60
|
|
61
61
|
$ /illustrations
|
62
62
|
|
63
|
+
The optional header graphics section is at:
|
64
|
+
|
65
|
+
$ /headers
|
66
|
+
|
63
67
|
... and it should work out of the box
|
64
68
|
|
65
69
|
|
@@ -0,0 +1,49 @@
|
|
1
|
+
class HeadersController < ApplicationController
|
2
|
+
|
3
|
+
before_filter :authenticate
|
4
|
+
before_filter :authenticate_with_admin
|
5
|
+
|
6
|
+
def index
|
7
|
+
@headers = Header.by_recent.paginate(:page => params[:page], :per_page => 25)
|
8
|
+
switch_to_admin_layout
|
9
|
+
end
|
10
|
+
|
11
|
+
def show
|
12
|
+
@header = Header.find(params[:id])
|
13
|
+
switch_to_admin_layout
|
14
|
+
end
|
15
|
+
|
16
|
+
def new
|
17
|
+
@header = Header.new
|
18
|
+
switch_to_admin_layout
|
19
|
+
end
|
20
|
+
|
21
|
+
def edit
|
22
|
+
@header = Header.find(params[:id])
|
23
|
+
switch_to_admin_layout
|
24
|
+
end
|
25
|
+
|
26
|
+
def create
|
27
|
+
@header = Header.new(params[:header])
|
28
|
+
if @header.save
|
29
|
+
redirect_to @header, notice: 'Header was successfully created.'
|
30
|
+
else
|
31
|
+
render action: "new", layout: 'admin'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def update
|
36
|
+
@header = Header.find(params[:id])
|
37
|
+
if @header.update_attributes(params[:header])
|
38
|
+
redirect_to @header, notice: 'Header was successfully updated.'
|
39
|
+
else
|
40
|
+
render action: "edit", layout: 'admin'
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
def destroy
|
45
|
+
@header = Header.find(params[:id])
|
46
|
+
@header.destroy
|
47
|
+
redirect_to headers_url
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# this is needed for now to make mass assignment security compatible with the translation of globalize3
|
2
|
+
Globalize::ActiveRecord::Translation.class_eval do
|
3
|
+
attr_accessible :locale
|
4
|
+
end
|
5
|
+
|
6
|
+
class Header < ActiveRecord::Base
|
7
|
+
|
8
|
+
attr_accessible :photo, :name
|
9
|
+
|
10
|
+
validates_presence_of :name
|
11
|
+
|
12
|
+
translates :name
|
13
|
+
|
14
|
+
mount_uploader :photo, PhotoUploader
|
15
|
+
|
16
|
+
def to_param
|
17
|
+
name ? "#{id}-#{name.to_url}" : id
|
18
|
+
end
|
19
|
+
|
20
|
+
scope :by_recent, :order => 'updated_at desc'
|
21
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
class PhotoUploader < CarrierWave::Uploader::Base
|
4
|
+
|
5
|
+
# Include RMagick or MiniMagick support:
|
6
|
+
include CarrierWave::RMagick
|
7
|
+
# include CarrierWave::MiniMagick
|
8
|
+
|
9
|
+
# Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
|
10
|
+
# include Sprockets::Helpers::RailsHelper
|
11
|
+
# include Sprockets::Helpers::IsolatedHelper
|
12
|
+
|
13
|
+
# Choose what kind of storage to use for this uploader:
|
14
|
+
storage :file
|
15
|
+
# storage :fog
|
16
|
+
|
17
|
+
# Override the directory where uploaded files will be stored.
|
18
|
+
# This is a sensible default for uploaders that are meant to be mounted:
|
19
|
+
def store_dir
|
20
|
+
# "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" --- that was the suggested one
|
21
|
+
"system/photos/#{model.class.to_s.underscore}/#{model.id}"
|
22
|
+
end
|
23
|
+
|
24
|
+
# Provide a default URL as a default if there hasn't been a file uploaded:
|
25
|
+
# def default_url
|
26
|
+
# # For Rails 3.1+ asset pipeline compatibility:
|
27
|
+
# # asset_path("fallback/" + [version_name, "default.png"].compact.join('_'))
|
28
|
+
#
|
29
|
+
# "/photos/fallback/" + [version_name, "default.png"].compact.join('_')
|
30
|
+
# end
|
31
|
+
|
32
|
+
# Process files as they are uploaded:
|
33
|
+
# process :scale => [200, 300]
|
34
|
+
#
|
35
|
+
# def scale(width, height)
|
36
|
+
# # do something
|
37
|
+
# end
|
38
|
+
|
39
|
+
# Create different versions of your uploaded files:
|
40
|
+
# version :thumb do
|
41
|
+
# process :scale => [50, 50]
|
42
|
+
# end
|
43
|
+
# version :thumbnail do
|
44
|
+
# process :resize_to_limit => [125, 125]
|
45
|
+
# end
|
46
|
+
version(:thumbnail) { process :resize_to_limit => [125, 125] }
|
47
|
+
version(:large) { process :resize_to_limit => [1170, 1170] }
|
48
|
+
|
49
|
+
# Add a white list of extensions which are allowed to be uploaded.
|
50
|
+
# For photos you might use something like this:
|
51
|
+
def extension_white_list
|
52
|
+
%w(jpg jpeg png)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Override the filename of the uploaded files:
|
56
|
+
# Avoid using model.id or version_name here, see uploader/store.rb for details.
|
57
|
+
# def filename
|
58
|
+
# "something.jpg" if original_filename
|
59
|
+
# end
|
60
|
+
|
61
|
+
# got this from http://stackoverflow.com/questions/9561641/carrierwave-temp-directory-set-to-uploads-tmp-folder
|
62
|
+
# without this all tmp files would go to /public/uploads/tmp which is not cool at all.
|
63
|
+
def cache_dir
|
64
|
+
# should return path to cache dir
|
65
|
+
Rails.root.join 'tmp/uploads'
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<%= simple_form_for @header, :html => { multipart: true, class: 'form-horizontal' } do |f| %>
|
2
|
+
<%= f.error_notification %>
|
3
|
+
|
4
|
+
<div class="form-inputs">
|
5
|
+
<%= f.input :photo, hint: "Ideally all header photos should have the following characteristics: 72 dpi; a width of at least 1,170 pixels; a ratio of 1170X273" %>
|
6
|
+
<%= f.input :name %>
|
7
|
+
</div>
|
8
|
+
|
9
|
+
<div class="form-actions">
|
10
|
+
<%= f.button :submit, :class => 'btn btn-primary' %>
|
11
|
+
<%= link_to 'Cancel & Show all Headers', headers_path, :class => 'btn' %>
|
12
|
+
</div>
|
13
|
+
<% end %>
|
@@ -0,0 +1,32 @@
|
|
1
|
+
<h1>Site Header Graphics</h1>
|
2
|
+
|
3
|
+
<table class='table table-striped'>
|
4
|
+
<thead>
|
5
|
+
<tr>
|
6
|
+
<th>Photo</th>
|
7
|
+
<th>Name & Paths</th>
|
8
|
+
<th>Actions</th>
|
9
|
+
</tr>
|
10
|
+
</thead>
|
11
|
+
|
12
|
+
<tbody>
|
13
|
+
<% @headers.each do |header| %>
|
14
|
+
<tr>
|
15
|
+
<td><%= link_to image_tag(header.photo.thumbnail), header %></td>
|
16
|
+
<td>
|
17
|
+
<h3><%= header.name %> | <%= link_to(' See all resolutions', header) %></h3>
|
18
|
+
<b>Thumbnail</b> path: <%= header.photo.thumbnail %><br />
|
19
|
+
<b>Large</b> path: <%= header.photo.large %><br />
|
20
|
+
</td>
|
21
|
+
<td><%= link_to 'Edit', edit_header_path(header), class: 'btn btn-mini' %>
|
22
|
+
<%= link_to 'Destroy', header, method: :delete, data: { confirm: 'Are you sure?' }, class: 'btn btn-mini btn-danger' %></td>
|
23
|
+
</tr>
|
24
|
+
<% end %>
|
25
|
+
</tbody>
|
26
|
+
</table>
|
27
|
+
|
28
|
+
<%= will_paginate @headers %>
|
29
|
+
|
30
|
+
<%= link_to 'Create New Header Graphic', new_header_path, class: 'btn btn-primary' %>
|
31
|
+
|
32
|
+
<%= render 'shared/admin_sidebar' %>
|
@@ -0,0 +1,16 @@
|
|
1
|
+
<% content_for :meta_title, @header.name %>
|
2
|
+
<% content_for :meta_description, @header.name %>
|
3
|
+
|
4
|
+
<h1>View a Header Graphic</h1>
|
5
|
+
|
6
|
+
<h3>Name: <%= @header.name %></h3>
|
7
|
+
<p>
|
8
|
+
<%= image_tag @header.photo.thumbnail %><br /><%= @header.photo.thumbnail %><br /><br />
|
9
|
+
<%= image_tag @header.photo.large %><br /><%= @header.photo.large %>
|
10
|
+
</p>
|
11
|
+
|
12
|
+
<%= link_to 'edit', edit_header_path(@header), :class => 'btn btn-mini' %>
|
13
|
+
<%= link_to 'all header graphics', headers_path, class: 'btn btn-mini' %>
|
14
|
+
<%= link_to 'upload new header grahpic', new_header_path, class: 'btn btn-mini' %>
|
15
|
+
|
16
|
+
<%= render 'shared/admin_sidebar' %>
|
data/config/routes.rb
CHANGED
@@ -20,6 +20,8 @@ module TkhIllustrations
|
|
20
20
|
migration_template "create_illustrations.rb", "db/migrate/create_illustrations.rb"
|
21
21
|
puts 'Adding translation of name attribute for Globalize3'
|
22
22
|
migration_template "add_translation_of_name_to_illustrations.rb", "db/migrate/add_translation_of_name_to_illustrations.rb"
|
23
|
+
puts 'Creating the headers table'
|
24
|
+
migration_template "create_headers.rb", "db/migrate/create_headers.rb"
|
23
25
|
end
|
24
26
|
|
25
27
|
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
class CreateHeaders < ActiveRecord::Migration
|
2
|
+
def up
|
3
|
+
create_table :headers do |t|
|
4
|
+
t.string :name
|
5
|
+
t.string :photo
|
6
|
+
t.timestamps
|
7
|
+
end
|
8
|
+
Header.create_translation_table!({ name: :string })
|
9
|
+
end
|
10
|
+
|
11
|
+
def down
|
12
|
+
drop_table :headers
|
13
|
+
Header.drop_translation_table!
|
14
|
+
end
|
15
|
+
end
|
@@ -2,6 +2,12 @@ namespace :tkh_illustrations do
|
|
2
2
|
|
3
3
|
desc "Create migration and locale files"
|
4
4
|
task :install do
|
5
|
+
system 'rails g tkh_illustrations:create_or_update_migrations'
|
6
|
+
system 'rails g tkh_illustrations:create_or_update_locales -f'
|
7
|
+
end
|
8
|
+
|
9
|
+
desc "Update files. Skip existing migrations. Force overwrite locales"
|
10
|
+
task :update do
|
5
11
|
system 'rails g tkh_illustrations:create_or_update_migrations -s'
|
6
12
|
system 'rails g tkh_illustrations:create_or_update_locales -f'
|
7
13
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: tkh_illustrations
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: '0.1'
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-11-04 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rails
|
@@ -146,9 +146,17 @@ executables: []
|
|
146
146
|
extensions: []
|
147
147
|
extra_rdoc_files: []
|
148
148
|
files:
|
149
|
+
- app/controllers/headers_controller.rb
|
149
150
|
- app/controllers/illustrations_controller.rb
|
151
|
+
- app/models/header.rb
|
150
152
|
- app/models/illustration.rb
|
151
153
|
- app/uploaders/image_uploader.rb
|
154
|
+
- app/uploaders/photo_uploader.rb
|
155
|
+
- app/views/headers/_form.html.erb
|
156
|
+
- app/views/headers/edit.html.erb
|
157
|
+
- app/views/headers/index.html.erb
|
158
|
+
- app/views/headers/new.html.erb
|
159
|
+
- app/views/headers/show.html.erb
|
152
160
|
- app/views/illustrations/_form.html.erb
|
153
161
|
- app/views/illustrations/edit.html.erb
|
154
162
|
- app/views/illustrations/index.html.erb
|
@@ -162,6 +170,7 @@ files:
|
|
162
170
|
- lib/generators/tkh_illustrations/create_or_update_locales/templates/fr.yml
|
163
171
|
- lib/generators/tkh_illustrations/create_or_update_migrations/create_or_update_migrations_generator.rb
|
164
172
|
- lib/generators/tkh_illustrations/create_or_update_migrations/templates/add_translation_of_name_to_illustrations.rb
|
173
|
+
- lib/generators/tkh_illustrations/create_or_update_migrations/templates/create_headers.rb
|
165
174
|
- lib/generators/tkh_illustrations/create_or_update_migrations/templates/create_illustrations.rb
|
166
175
|
- lib/tasks/tkh_illustrations_tasks.rake
|
167
176
|
- lib/tkh_illustrations/version.rb
|
@@ -214,7 +223,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
214
223
|
version: '0'
|
215
224
|
segments:
|
216
225
|
- 0
|
217
|
-
hash: -
|
226
|
+
hash: -1324274835237882850
|
218
227
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
219
228
|
none: false
|
220
229
|
requirements:
|
@@ -223,7 +232,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
223
232
|
version: '0'
|
224
233
|
segments:
|
225
234
|
- 0
|
226
|
-
hash: -
|
235
|
+
hash: -1324274835237882850
|
227
236
|
requirements: []
|
228
237
|
rubyforge_project:
|
229
238
|
rubygems_version: 1.8.23
|