gem 'papermill'
generate :papermill_table, "PapermillMigration"
generate :papermill_assets
generate :papermill_initializer
generate :scaffold, "article title:string"
rake "db:migrate"
file "app/models/article.rb", <<-END
class Article < ActiveRecord::Base
validates_presence_of :title
papermill :image_gallery, :thumbnail => {:width => 75, :height => 100}, :images_only => true # only images, custom preview thumbnail size
papermill :thumbnail, :swfupload => { :file_types => "*.jpg;*.jpeg" } # jpg only, cherry picking
papermill :my_assets
papermill :my_other_asset
end
END
file "app/views/articles/edit.html.erb", <<-END
Editing article
<%= render :partial => "form" %>
<%= link_to 'Show', @article %> |
<%= link_to 'Back', articles_path %>
END
file "app/views/articles/new.html.erb", <<-END
New article
<%= render :partial => "form" %>
<%= link_to 'Back', articles_path %>
END
file "app/views/articles/_form.html.erb", <<-END
<% form_for(@article) do |f| %>
<%= f.error_messages %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :image_gallery %>
<%= f.images_upload(:image_gallery) %>
<%= f.label :thumbnail %>
<%= f.image_upload(:thumbnail) %>
<%= f.label :my_assets %>
<%= f.assets_upload(:my_assets) %>
<%= f.label :my_other_asset %>
<%= f.asset_upload(:my_other_asset) %>
<%= f.submit 'Send' %>
<% end %>
END
file "app/views/articles/show.html.erb", <<-END
Title:
<%=h @article.title %>
@article.image_gallery.each :
<% @article.image_gallery.each do |image| %>
<%= link_to(image_tag(image.url("100x100#")), image.url) %>
<% end %>
@article.thumbnail.first :
<% image = @article.thumbnail.first %>
<%= link_to(image_tag(image.url("100x100#")), image.url) if image %>
@article.my_assets.each :
<% @article.my_assets.each do |asset| %>
- <%= link_to asset.name, asset.url %>
<% end %>
@article.my_other_asset.first :
<% asset = @article.my_other_asset.first %>
<%= link_to(asset.name, asset.url) if asset %>
<%= link_to 'Edit', edit_article_path(@article) %> |
<%= link_to 'Back', articles_path %>
END
file "app/views/layouts/application.html.erb", <<-END
Papermill Demo
<%= stylesheet_link_tag 'scaffold' %>
<%= papermill_stylesheet_tag %>
<%= yield %>
<%= papermill_javascript_tag :with_jquery => true %>
END
run "rm app/views/layouts/articles.html.erb"
run "rm public/index.html"
route "map.root :controller => 'articles'"