refinerycms-downloads 0.1.0

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.
@@ -0,0 +1,14 @@
1
+ module Admin
2
+ class DownloadsController < Admin::BaseController
3
+
4
+ crudify :download
5
+
6
+ def index
7
+ search_all_downloads if searching?
8
+ paginate_all_downloads
9
+
10
+ render :partial => 'downloads' if request.xhr?
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,31 @@
1
+ class DownloadsController < ApplicationController
2
+
3
+ before_filter :find_all_downloads
4
+ before_filter :find_page
5
+ before_filter :authorize_as_private_user
6
+
7
+ def index
8
+ # you can use meta fields from your model instead (e.g. browser_title)
9
+ # by swapping @page for @download in the line below:
10
+ present(@page)
11
+ end
12
+
13
+ protected
14
+
15
+ def find_all_downloads
16
+ @downloads = Download.find(:all, :order => "position ASC")
17
+ end
18
+
19
+ def find_page
20
+ @page = Page.find_by_link_url("/downloads")
21
+ end
22
+
23
+ def authorize_as_private_user
24
+ if current_user
25
+ redirect_to root_url unless current_user.has_role?(:downloads)
26
+ elsif !current_user
27
+ redirect_to new_user_session_path
28
+ end
29
+ end
30
+
31
+ end
@@ -0,0 +1,13 @@
1
+ module DownloadsHelper
2
+ def fileicon(download)
3
+ if Download::ICONS.include?(download.file.file_ext)
4
+ image_tag("#{download.file.file_ext}.png")
5
+ else
6
+ image_tag('page_white.png')
7
+ end
8
+ end
9
+
10
+ def filelink(download)
11
+ "onclick=\"window.location.href='#{download.file.url}';\" ".html_safe
12
+ end
13
+ end
@@ -0,0 +1,11 @@
1
+ class Download < ActiveRecord::Base
2
+
3
+ acts_as_indexed :fields => [:title]
4
+
5
+ validates :title, :presence => true, :uniqueness => true
6
+
7
+ belongs_to :file, :class_name => 'Resource'
8
+
9
+ ICONS = [ 'pdf', 'doc' ]
10
+
11
+ end
@@ -0,0 +1,18 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(download) -%>">
2
+ <span class='title'>
3
+ <%= download.title %>
4
+ <span class="preview">&nbsp;</span>
5
+ </span>
6
+ <span class='actions'>
7
+ <%= link_to refinery_icon_tag("application_go.png"), download_url(download),
8
+ :title => t('.view_live_html'),
9
+ :target => "_blank" %>
10
+ <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_download_path(download),
11
+ :title => t('.edit') %>
12
+ <%= link_to refinery_icon_tag("delete.png"), admin_download_path(download),
13
+ :class => "cancel confirm-delete",
14
+ :title => t('.delete'),
15
+ :confirm => t('message', :scope => 'shared.admin.delete', :title => download.title),
16
+ :method => :delete %>
17
+ </span>
18
+ </li>
@@ -0,0 +1,2 @@
1
+ <%= will_paginate @downloads %>
2
+ <%= render :partial => "sortable_list" %>
@@ -0,0 +1,28 @@
1
+ <%= form_for [:admin, @download] do |f| -%>
2
+ <%= render :partial => "/shared/admin/error_messages", :locals => {
3
+ :object => @download,
4
+ :include_object_name => true
5
+ } %>
6
+
7
+ <div class='field'>
8
+ <%= f.label :title -%>
9
+ <%= f.text_field :title, :class => 'larger widest' -%>
10
+ </div>
11
+
12
+ <div class='field'>
13
+ <%= f.label :file -%>
14
+ <%= render :partial => "/shared/admin/resource_picker", :locals => {
15
+ :f => f,
16
+ :field => :file_id,
17
+ :resource => @download.file,
18
+ } %>
19
+ </div>
20
+
21
+ <%= render :partial => "/shared/admin/form_actions",
22
+ :locals => {
23
+ :f => f,
24
+ :continue_editing => false,
25
+ :delete_title => t('delete', :scope => 'admin.downloads.download'),
26
+ :delete_confirmation => t('message', :scope => 'shared.admin.delete', :title => @download.title)
27
+ } %>
28
+ <% end -%>
@@ -0,0 +1,7 @@
1
+ <ul id='sortable_list'>
2
+ <%= render :partial => 'download', :collection => @downloads %>
3
+ </ul>
4
+ <%= render :partial => "/shared/admin/sortable_list",
5
+ :locals => {
6
+ :continue_reordering => (local_assigns.keys.include?(:continue_reordering)) ? continue_reordering : true
7
+ } %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,54 @@
1
+ <div id='records'>
2
+ <% if searching? %>
3
+ <h2><%= t('results_for', :scope => 'shared.admin.search', :query => params[:search]) %></h2>
4
+ <% end %>
5
+ <% if @downloads.any? %>
6
+ <div class='pagination_container'>
7
+ <%= render :partial => 'downloads' %>
8
+ </div>
9
+ <% else %>
10
+ <p>
11
+ <% unless searching? %>
12
+ <strong>
13
+ <%= t('.no_items_yet') %>
14
+ </strong>
15
+ <% else %>
16
+ <%= t('no_results', :scope => 'shared.admin.search') %>
17
+ <% end %>
18
+ </p>
19
+ <% end %>
20
+ </div>
21
+ <div id='actions'>
22
+ <ul>
23
+ <% if Admin::DownloadsController.searchable? %>
24
+ <li>
25
+ <%= render :partial => "/shared/admin/search",
26
+ :locals => {
27
+ :url => admin_downloads_url
28
+ } %>
29
+ </li>
30
+ <% end %>
31
+ <li>
32
+ <%= link_to t('.create_new'), new_admin_download_url,
33
+ :class => "add_icon" %>
34
+ </li>
35
+ <% if !searching? and Admin::DownloadsController.sortable? and Download.count > 1 %>
36
+ <li>
37
+ <%= link_to t('.reorder', :what => "Downloads"),
38
+ admin_downloads_url,
39
+ :id => "reorder_action",
40
+ :class => "reorder_icon" %>
41
+
42
+ <%= link_to t('.reorder_done', :what => "Downloads"),
43
+ admin_downloads_url,
44
+ :id => "reorder_action_done",
45
+ :style => "display: none;",
46
+ :class => "reorder_icon" %>
47
+ </li>
48
+ <% end %>
49
+ </ul>
50
+ </div>
51
+ <%= render :partial => "/shared/admin/make_sortable",
52
+ :locals => {
53
+ :tree => false
54
+ } if !searching? and Admin::DownloadsController.sortable? and Download.count > 1 %>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,19 @@
1
+ <% content_for :body_content_left do %>
2
+ <%= raw @page[:body] %>
3
+ <table class="download full">
4
+ <tr>
5
+ <th><%= t('.filename') %></th>
6
+ <th><%= t('.filesize') %></th>
7
+ <th><%= t('.filetype') %></th>
8
+ </tr>
9
+ <% @downloads.each do |download| %>
10
+ <tr <%= filelink(download) %>>
11
+ <td><%= download.title %></td>
12
+ <td><%= number_to_human_size(download.file.file_size) %></td>
13
+ <td><%= link_to fileicon(download), download.file.url, :target => '_blank' %></td>
14
+ </tr>
15
+ <% end %>
16
+ </table>
17
+ <% end %>
18
+
19
+ <%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,33 @@
1
+ <% content_for :body_content_title do %>
2
+ <%= @download.title %>
3
+ <% end %>
4
+
5
+ <% content_for :body_content_left do %>
6
+ <section>
7
+ <h1>Title</h1>
8
+ <p>
9
+ <%=raw @download.title %>
10
+ </p>
11
+ </section>
12
+ <section>
13
+ <h1>File</h1>
14
+ <p>
15
+ <%= link_to 'file', @download.file.url %>
16
+ </p>
17
+ </section>
18
+ <% end %>
19
+
20
+ <% content_for :body_content_right do %>
21
+ <aside>
22
+ <h2><%= t('.other') %></h2>
23
+ <ul id="downloads">
24
+ <% @downloads.each do |download| %>
25
+ <li>
26
+ <%= link_to download.title, download_url(download) %>
27
+ </li>
28
+ <% end %>
29
+ </ul>
30
+ </aside>
31
+ <% end %>
32
+
33
+ <%= render :partial => "/shared/content_page" %>
@@ -0,0 +1,29 @@
1
+ en:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: image
6
+ plugins:
7
+ downloads:
8
+ title: Downloads
9
+ admin:
10
+ downloads:
11
+ index:
12
+ title: Downloads
13
+ create_new: Add New Download
14
+ reorder: Reorder Downloads
15
+ reorder_done: Done Reordering Downloads
16
+ sorry_no_results: Sorry! There are no results found.
17
+ no_items_yet: There are no Downloads yet. Click "Add New Download" to add your first download.
18
+ download:
19
+ view_live_html: View this download live <br/><em>(opens in a new window)</em>
20
+ edit: Edit this download
21
+ delete: Remove this download forever
22
+ downloads:
23
+ index:
24
+ filename: Filename
25
+ filetype: Type
26
+ filesize: Size
27
+ show:
28
+ other: Other Downloads
29
+
@@ -0,0 +1,24 @@
1
+ lolcat:
2
+ shared:
3
+ admin:
4
+ image_picker:
5
+ image: IMAGE
6
+ plugins:
7
+ downloads:
8
+ title: Downloads
9
+ admin:
10
+ downloads:
11
+ index:
12
+ title: Downloads
13
+ create_new: CREATE NEW Download
14
+ reorder: REORDR Downloads
15
+ reorder_done: DUN REORDERIN Downloads
16
+ sorry_no_results: SRY! THAR R NO RESULTS FINDZ.
17
+ no_items_yet: THAR R NO Downloads YET. CLICK "CREATE NEW Download" 2 ADD UR FURST download.
18
+ download:
19
+ view_live_html: VIEW DIS download LIV <BR/><EM>(OPENS IN NEW WINDOW)</EM>
20
+ edit: EDIT DIS download
21
+ delete: REMOOV DIS download FOREVR
22
+ downloads:
23
+ show:
24
+ other: OTHR Downloads
@@ -0,0 +1,20 @@
1
+ nb:
2
+ plugins:
3
+ downloads:
4
+ title: Downloads
5
+ admin:
6
+ downloads:
7
+ index:
8
+ title: Downloads
9
+ create_new: Lag en ny Download
10
+ reorder: Endre rekkefølgen på Downloads
11
+ reorder_done: Ferdig å endre rekkefølgen Downloads
12
+ sorry_no_results: Beklager! Vi fant ikke noen resultater.
13
+ no_items_yet: Det er ingen Downloads enda. Klikk på "Lag en ny Download" for å legge til din første download.
14
+ download:
15
+ view_live_html: Vis hvordan denne download ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
16
+ edit: Rediger denne download
17
+ delete: Fjern denne download permanent
18
+ downloads:
19
+ show:
20
+ other: Andre Downloads
@@ -0,0 +1,20 @@
1
+ nl:
2
+ plugins:
3
+ downloads:
4
+ title: Downloads
5
+ admin:
6
+ downloads:
7
+ index:
8
+ title: Downloads
9
+ create_new: Maak een nieuwe Download
10
+ reorder: Wijzig de volgorde van de Downloads
11
+ reorder_done: Klaar met het wijzingen van de volgorde van de Downloads
12
+ sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
13
+ no_items_yet: Er zijn nog geen Downloads. Druk op 'Maak een nieuwe Download' om de eerste aan te maken.
14
+ download:
15
+ view_live_html: Bekijk deze download op de website <br/><em>(opent een nieuw venster)</em>
16
+ edit: Bewerk deze download
17
+ delete: Verwijder deze download voor eeuwig
18
+ downloads:
19
+ show:
20
+ other: Andere Downloads
data/config/routes.rb ADDED
@@ -0,0 +1,11 @@
1
+ Refinery::Application.routes.draw do
2
+ resources :downloads, :only => [:index, :show]
3
+
4
+ scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
5
+ resources :downloads, :except => :show do
6
+ collection do
7
+ post :update_positions
8
+ end
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ class RefinerycmsDownloads < Refinery::Generators::EngineInstaller
2
+
3
+ source_root File.expand_path('../../../', __FILE__)
4
+ engine_name "downloads"
5
+
6
+ end
@@ -0,0 +1,19 @@
1
+ require 'refinery'
2
+
3
+ module Refinery
4
+ module Downloads
5
+ class Engine < Rails::Engine
6
+ initializer "static assets" do |app|
7
+ app.middleware.insert_after ::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public"
8
+ end
9
+
10
+ config.after_initialize do
11
+ Refinery::Plugin.register do |plugin|
12
+ plugin.name = "downloads"
13
+ plugin.activity = {
14
+ :class => Download}
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :downloads do
4
+
5
+ # call this task my running: rake refinery:downloads:my_task
6
+ # desc "Description of my task below"
7
+ # task :my_task => :environment do
8
+ # # add your logic here
9
+ # end
10
+
11
+ end
12
+
13
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-downloads
3
+ version: !ruby/object:Gem::Version
4
+ hash: 27
5
+ prerelease:
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 0
10
+ version: 0.1.0
11
+ platform: ruby
12
+ authors:
13
+ - Stefan Mielke
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-03-01 17:23:28.805985 +01:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description: "Ruby on Rails Downloads engine for Refinery CMS. "
23
+ email: stefan@tan3.de
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files: []
29
+
30
+ files:
31
+ - lib/generators/refinerycms_downloads_generator.rb
32
+ - lib/refinerycms-downloads.rb
33
+ - lib/tasks/downloads.rake
34
+ - config/locales/en.yml
35
+ - config/locales/lolcat.yml
36
+ - config/locales/nb.yml
37
+ - config/locales/nl.yml
38
+ - config/routes.rb
39
+ - app/controllers/admin/downloads_controller.rb
40
+ - app/controllers/downloads_controller.rb
41
+ - app/helpers/downloads_helper.rb
42
+ - app/models/download.rb
43
+ - app/views/admin/downloads/_download.html.erb
44
+ - app/views/admin/downloads/_downloads.html.erb
45
+ - app/views/admin/downloads/_form.html.erb
46
+ - app/views/admin/downloads/_sortable_list.html.erb
47
+ - app/views/admin/downloads/edit.html.erb
48
+ - app/views/admin/downloads/index.html.erb
49
+ - app/views/admin/downloads/new.html.erb
50
+ - app/views/downloads/index.html.erb
51
+ - app/views/downloads/show.html.erb
52
+ has_rdoc: true
53
+ homepage: http://tan3.de
54
+ licenses: []
55
+
56
+ post_install_message:
57
+ rdoc_options: []
58
+
59
+ require_paths:
60
+ - lib
61
+ required_ruby_version: !ruby/object:Gem::Requirement
62
+ none: false
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ hash: 3
67
+ segments:
68
+ - 0
69
+ version: "0"
70
+ required_rubygems_version: !ruby/object:Gem::Requirement
71
+ none: false
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ hash: 3
76
+ segments:
77
+ - 0
78
+ version: "0"
79
+ requirements: []
80
+
81
+ rubyforge_project:
82
+ rubygems_version: 1.5.0
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Private Downloads engine for Refinery CMS
86
+ test_files: []
87
+