Navigation Menu

Skip to content

Commit

Permalink
* support image upload by Fleximage.
Browse files Browse the repository at this point in the history
  • Loading branch information
kou committed Mar 6, 2009
1 parent a5e18f9 commit 15f65ec
Show file tree
Hide file tree
Showing 168 changed files with 17,748 additions and 3 deletions.
1 change: 1 addition & 0 deletions README
Expand Up @@ -29,3 +29,4 @@ GPLv3 or AGPLv3 excepted the following softwares:
* public_html/extjs/: GPL 3.0. See public_html/extjs/license.txt.
* public_html/javascripts/ except aplication.js (i.e. Prototype Javascript framework): MIT license. See http://www.prototypejs.org/.
* vendor/plugins/rails-i18n/: MIT license?
* vendor/plugins/fleximage/: MIT license
1 change: 1 addition & 0 deletions README.ja.txt
Expand Up @@ -31,3 +31,4 @@ M17N CMSは静的なHTMLのサイト用のコンテンツ管理システムで
* public_html/extjs/: GPL 3.0。public_html/extjs/license.txtを見てください。
* public_html/javascripts/ ただしaplication.jsを除く(つまりPrototype Javascript frameworkのこと): MITライセンス。http://www.prototypejs.org/を見てください。
* vendor/plugins/rails-i18n/: MITライセンス?
* vendor/plugins/fleximage/: MITライセンス
88 changes: 88 additions & 0 deletions app/controllers/images_controller.rb
@@ -0,0 +1,88 @@
class ImagesController < ApplicationController
# GET /images
# GET /images.xml
def index
@images = Image.find(:all)

respond_to do |format|
format.html # index.html.erb
format.xml { render :xml => @images }
end
end

# GET /images/1
# GET /images/1.xml
def show
@image = Image.find(params[:id])

respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @image }
format.png
format.jpg
format.gif
end
end

# GET /images/new
# GET /images/new.xml
def new
@image = Image.new

respond_to do |format|
format.html # new.html.erb
format.xml { render :xml => @image }
end
end

# GET /images/1/edit
def edit
@image = Image.find(params[:id])
end

# POST /images
# POST /images.xml
def create
@image = Image.new(params[:image])

respond_to do |format|
if @image.save
flash[:notice] = 'Image was successfully created.'
format.html { redirect_to(@image) }
format.xml { render :xml => @image, :status => :created, :location => @image }
else
format.html { render :action => "new" }
format.xml { render :xml => @image.errors, :status => :unprocessable_entity }
end
end
end

# PUT /images/1
# PUT /images/1.xml
def update
@image = Image.find(params[:id])

respond_to do |format|
if @image.update_attributes(params[:image])
flash[:notice] = 'Image was successfully updated.'
format.html { redirect_to(@image) }
format.xml { head :ok }
else
format.html { render :action => "edit" }
format.xml { render :xml => @image.errors, :status => :unprocessable_entity }
end
end
end

# DELETE /images/1
# DELETE /images/1.xml
def destroy
@image = Image.find(params[:id])
@image.destroy

respond_to do |format|
format.html { redirect_to(images_url) }
format.xml { head :ok }
end
end
end
2 changes: 2 additions & 0 deletions app/helpers/images_helper.rb
@@ -0,0 +1,2 @@
module ImagesHelper
end
15 changes: 15 additions & 0 deletions app/models/image.rb
@@ -0,0 +1,15 @@
class Image < ActiveRecord::Base
acts_as_fleximage :image_directory => File.join("images", "uploaded")

def image_filename=(filename)
self.filename = filename
end

def image_width=(width)
self.width = width
end

def image_height=(height)
self.height = height
end
end
7 changes: 4 additions & 3 deletions app/views/contents/edit.html.erb
Expand Up @@ -46,7 +46,7 @@ Ext.onReady(function() {
// General options
mode : "textareas",
theme : "advanced",
plugins : "safari,pagebreak,style,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking#{ruby_plugin},xhtmlxtras,autosave",
plugins : "safari,pagebreak,style,table,save,advhr,advimage,imageupload,advlink,emotions,iespell,inlinepopups,insertdatetime,media,searchreplace,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking#{ruby_plugin},xhtmlxtras,autosave",
// Theme options
theme_advanced_buttons1 : "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,styleselect,formatselect,fontselect,fontsizeselect",
Expand All @@ -62,8 +62,9 @@ Ext.onReady(function() {
// content_css : "css/content.css",
// Drop lists for link/image/media/template dialogs
external_link_list_url : #{formatted_links_content_path(@content, "js").to_json},
external_image_list_url : "lists/image_list.js",
external_link_list_url : #{links_content_path(@content, :format => "js").to_json},
image_upload_url: #{images_url.to_json},
language: #{@content.tiny_mcs_language.to_json}
});
Expand Down
24 changes: 24 additions & 0 deletions app/views/images/edit.html.erb
@@ -0,0 +1,24 @@
<h1>Editing image</h1>

<% form_for(@image) do |f| %>
<%= f.error_messages %>

<p>
<%= f.label :filename %><br />
<%= f.text_field :filename %>
</p>
<p>
<%= f.label :width %><br />
<%= f.text_field :width %>
</p>
<p>
<%= f.label :height %><br />
<%= f.text_field :height %>
</p>
<p>
<%= f.submit "Update" %>
</p>
<% end %>
<%= link_to 'Show', @image %> |
<%= link_to 'Back', images_path %>
24 changes: 24 additions & 0 deletions app/views/images/index.html.erb
@@ -0,0 +1,24 @@
<h1>Listing images</h1>

<table>
<tr>
<th>Filename</th>
<th>Width</th>
<th>Height</th>
</tr>

<% for image in @images %>
<tr>
<td><%=h image.filename %></td>
<td><%=h image.width %></td>
<td><%=h image.height %></td>
<td><%= link_to 'Show', image %></td>
<td><%= link_to 'Edit', edit_image_path(image) %></td>
<td><%= link_to 'Destroy', image, :confirm => 'Are you sure?', :method => :delete %></td>
</tr>
<% end %>
</table>

<br />

<%= link_to 'New image', new_image_path %>
15 changes: 15 additions & 0 deletions app/views/images/new.html.erb
@@ -0,0 +1,15 @@
<h1>New image</h1>

<% form_for(@image, :html => {:multipart => true}) do |f| %>
<%= f.error_messages %>

<p>
<%= f.file_field :image_file %><br />
or URL: <%= f.text_field :image_file_url %>
</p>
<p>
<%= f.submit "Create" %>
</p>
<% end %>
<%= link_to 'Back', images_path %>
3 changes: 3 additions & 0 deletions app/views/images/show.gif.flexi
@@ -0,0 +1,3 @@
@image.operate do |image|
image.resize '320x240'
end
23 changes: 23 additions & 0 deletions app/views/images/show.html.erb
@@ -0,0 +1,23 @@
<p>
<b>Image:</b>
<%= image_tag(image_path(@image, :format => :png)) %>
</p>

<p>
<b>Filename:</b>
<%=h @image.filename %>
</p>

<p>
<b>Width:</b>
<%=h @image.width %>
</p>

<p>
<b>Height:</b>
<%=h @image.height %>
</p>


<%= link_to 'Edit', edit_image_path(@image) %> |
<%= link_to 'Back', images_path %>
3 changes: 3 additions & 0 deletions app/views/images/show.jpg.flexi
@@ -0,0 +1,3 @@
@image.operate do |image|
image.resize '320x240'
end
3 changes: 3 additions & 0 deletions app/views/images/show.png.flexi
@@ -0,0 +1,3 @@
@image.operate do |image|
image.resize '320x240'
end
17 changes: 17 additions & 0 deletions app/views/layouts/images.html.erb
@@ -0,0 +1,17 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="content-type" content="text/html;charset=UTF-8" />
<title>Images: <%= controller.action_name %></title>
<%= stylesheet_link_tag('base') %>
</head>
<body>

<p style="color: green"><%= flash[:notice] %></p>

<%= yield %>

</body>
</html>
2 changes: 2 additions & 0 deletions config/routes.rb
@@ -1,4 +1,6 @@
ActionController::Routing::Routes.draw do |map|
map.resources :images

map.resources :sites, :member => {:upload => :post, :upload_status => :get}

map.resources :contents,
Expand Down
15 changes: 15 additions & 0 deletions db/migrate/20090306025602_create_images.rb
@@ -0,0 +1,15 @@
class CreateImages < ActiveRecord::Migration
def self.up
create_table :images do |t|
t.string :filename
t.integer :width
t.integer :height

t.timestamps
end
end

def self.down
drop_table :images
end
end
1 change: 1 addition & 0 deletions public/images/.gitignore
@@ -0,0 +1 @@
/uploaded
11 changes: 11 additions & 0 deletions test/fixtures/images.yml
@@ -0,0 +1,11 @@
# Read about fixtures at http://ar.rubyonrails.org/classes/Fixtures.html

one:
filename: MyString
width: 1
height:

two:
filename: MyString
width: 1
height:
45 changes: 45 additions & 0 deletions test/functional/images_controller_test.rb
@@ -0,0 +1,45 @@
require 'test_helper'

class ImagesControllerTest < ActionController::TestCase
test "should get index" do
get :index
assert_response :success
assert_not_nil assigns(:images)
end

test "should get new" do
get :new
assert_response :success
end

test "should create image" do
assert_difference('Image.count') do
post :create, :image => { }
end

assert_redirected_to image_path(assigns(:image))
end

test "should show image" do
get :show, :id => images(:one).id
assert_response :success
end

test "should get edit" do
get :edit, :id => images(:one).id
assert_response :success
end

test "should update image" do
put :update, :id => images(:one).id, :image => { }
assert_redirected_to image_path(assigns(:image))
end

test "should destroy image" do
assert_difference('Image.count', -1) do
delete :destroy, :id => images(:one).id
end

assert_redirected_to images_path
end
end
8 changes: 8 additions & 0 deletions test/unit/image_test.rb
@@ -0,0 +1,8 @@
require 'test_helper'

class ImageTest < ActiveSupport::TestCase
# Replace this with your real tests.
test "the truth" do
assert true
end
end
5 changes: 5 additions & 0 deletions vendor/plugins/fleximage/.gitignore
@@ -0,0 +1,5 @@
test/rails_root/log/*
test/rails_root/public/uploads/*
test/rails_root/tmp/**/*
.DS_Store
*.sqlite3
20 changes: 20 additions & 0 deletions vendor/plugins/fleximage/MIT-LICENSE
@@ -0,0 +1,20 @@
Copyright (c) 2008 [name of plugin creator]

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

0 comments on commit 15f65ec

Please sign in to comment.