refinerycms-widgets 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/app/controllers/refinery/widgets/admin/widgets_controller.rb +12 -0
- data/app/controllers/refinery/widgets/widgets_controller.rb +34 -0
- data/app/models/refinery/widgets/widget.rb +13 -0
- data/app/views/refinery/widgets/admin/widgets/_actions.html.erb +25 -0
- data/app/views/refinery/widgets/admin/widgets/_form.html.erb +44 -0
- data/app/views/refinery/widgets/admin/widgets/_records.html.erb +18 -0
- data/app/views/refinery/widgets/admin/widgets/_sortable_list.html.erb +5 -0
- data/app/views/refinery/widgets/admin/widgets/_widget.html.erb +20 -0
- data/app/views/refinery/widgets/admin/widgets/_widgets.html.erb +2 -0
- data/app/views/refinery/widgets/admin/widgets/edit.html.erb +1 -0
- data/app/views/refinery/widgets/admin/widgets/index.html.erb +7 -0
- data/app/views/refinery/widgets/admin/widgets/new.html.erb +1 -0
- data/app/views/refinery/widgets/widgets/index.html.erb +11 -0
- data/app/views/refinery/widgets/widgets/show.html.erb +33 -0
- data/config/locales/en.yml +28 -0
- data/config/locales/es.yml +29 -0
- data/config/locales/fr.yml +28 -0
- data/config/locales/nb.yml +28 -0
- data/config/locales/nl.yml +28 -0
- data/config/locales/sk.yml +28 -0
- data/config/locales/zh-CN.yml +30 -0
- data/config/routes.rb +19 -0
- data/db/migrate/1_create_widgets_widgets.rb +27 -0
- data/db/seeds.rb +25 -0
- data/lib/generators/refinery/widgets_generator.rb +19 -0
- data/lib/refinery/widgets.rb +24 -0
- data/lib/refinery/widgets/engine.rb +27 -0
- data/lib/refinery/widgets/middleware.rb +35 -0
- data/lib/refinerycms-widgets.rb +1 -0
- data/lib/tasks/refinery/widgets.rake +13 -0
- data/readme.md +48 -0
- metadata +107 -0
@@ -0,0 +1,34 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Widgets
|
3
|
+
class WidgetsController < ::ApplicationController
|
4
|
+
|
5
|
+
before_filter :find_all_widgets
|
6
|
+
before_filter :find_page
|
7
|
+
|
8
|
+
def index
|
9
|
+
# you can use meta fields from your model instead (e.g. browser_title)
|
10
|
+
# by swapping @page for @widget in the line below:
|
11
|
+
present(@page)
|
12
|
+
end
|
13
|
+
|
14
|
+
def show
|
15
|
+
@widget = Widget.find(params[:id])
|
16
|
+
|
17
|
+
# you can use meta fields from your model instead (e.g. browser_title)
|
18
|
+
# by swapping @page for @widget in the line below:
|
19
|
+
present(@page)
|
20
|
+
end
|
21
|
+
|
22
|
+
protected
|
23
|
+
|
24
|
+
def find_all_widgets
|
25
|
+
@widgets = Widget.order('position ASC')
|
26
|
+
end
|
27
|
+
|
28
|
+
def find_page
|
29
|
+
@page = ::Refinery::Page.where(:link_url => "/widgets").first
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Widgets
|
3
|
+
class Widget < Refinery::Core::BaseModel
|
4
|
+
self.table_name = 'refinery_widgets'
|
5
|
+
|
6
|
+
attr_accessible :name, :content, :position
|
7
|
+
|
8
|
+
acts_as_indexed :fields => [:name, :content]
|
9
|
+
|
10
|
+
validates :name, :presence => true, :uniqueness => true
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<ul>
|
2
|
+
<% if ::Refinery::Widgets::Admin::WidgetsController.searchable? %>
|
3
|
+
<li>
|
4
|
+
<%= render '/refinery/admin/search', :url => refinery.widgets_admin_widgets_path %>
|
5
|
+
</li>
|
6
|
+
<% end %>
|
7
|
+
<li>
|
8
|
+
<%= link_to t('.create_new'), refinery.new_widgets_admin_widget_path,
|
9
|
+
:class => "add_icon" %>
|
10
|
+
</li>
|
11
|
+
<% if !searching? && ::Refinery::Widgets::Admin::WidgetsController.sortable? && ::Refinery::Widgets::Widget.any? %>
|
12
|
+
<li>
|
13
|
+
<%= link_to t('.reorder', :what => "Widgets"),
|
14
|
+
refinery.widgets_admin_widgets_path,
|
15
|
+
:id => "reorder_action",
|
16
|
+
:class => "reorder_icon" %>
|
17
|
+
|
18
|
+
<%= link_to t('.reorder_done', :what => "Widgets"),
|
19
|
+
refinery.widgets_admin_widgets_path,
|
20
|
+
:id => "reorder_action_done",
|
21
|
+
:style => "display: none;",
|
22
|
+
:class => "reorder_icon" %>
|
23
|
+
</li>
|
24
|
+
<% end %>
|
25
|
+
</ul>
|
@@ -0,0 +1,44 @@
|
|
1
|
+
<%= form_for [refinery, :widgets_admin, @widget] do |f| -%>
|
2
|
+
<%= render '/refinery/admin/error_messages',
|
3
|
+
:object => @widget,
|
4
|
+
:include_object_name => true %>
|
5
|
+
|
6
|
+
|
7
|
+
<div class='field'>
|
8
|
+
<%= f.label :name -%>
|
9
|
+
<%= f.text_field :name, :class => 'larger widest' -%>
|
10
|
+
|
11
|
+
</div>
|
12
|
+
|
13
|
+
<div class='field'>
|
14
|
+
<div id='page-tabs' class='clearfix ui-tabs ui-widget ui-widget-content ui-corner-all'>
|
15
|
+
<ul id='page_parts'>
|
16
|
+
<% [:content].each_with_index do |part, part_index| %>
|
17
|
+
<li class='ui-state-default<%= ' ui-state-active' if part_index == 0 %>'>
|
18
|
+
<%= link_to t("#{part}", :scope => "activerecord.attributes.refinery/widgets/widget", :default => part.to_s.titleize), "##{part}" %>
|
19
|
+
</li>
|
20
|
+
<% end %>
|
21
|
+
</ul>
|
22
|
+
<div id='page_part_editors'>
|
23
|
+
<% [:content].each do |part| %>
|
24
|
+
<div class='page_part' id='<%= part %>'>
|
25
|
+
<%= f.text_area part, :rows => 20, :class => 'wymeditor widest' -%>
|
26
|
+
</div>
|
27
|
+
<% end %>
|
28
|
+
</div>
|
29
|
+
</div>
|
30
|
+
|
31
|
+
</div>
|
32
|
+
|
33
|
+
<%= render '/refinery/admin/form_actions', :f => f,
|
34
|
+
:continue_editing => false,
|
35
|
+
:delete_title => t('delete', :scope => 'refinery.widgets.admin.widgets.widget'),
|
36
|
+
:delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @widget.name) %>
|
37
|
+
<% end -%>
|
38
|
+
<% content_for :javascripts do %>
|
39
|
+
<script>
|
40
|
+
$(document).ready(function(){
|
41
|
+
page_options.init(false, '', '');
|
42
|
+
});
|
43
|
+
</script>
|
44
|
+
<% end %>
|
@@ -0,0 +1,18 @@
|
|
1
|
+
<% if searching? %>
|
2
|
+
<h2><%= t('results_for', :scope => 'refinery.admin.search', :query => params[:search]) %></h2>
|
3
|
+
<% end %>
|
4
|
+
<div class='pagination_container'>
|
5
|
+
<% if @widgets.any? %>
|
6
|
+
<%= render 'widgets' %>
|
7
|
+
<% else %>
|
8
|
+
<p>
|
9
|
+
<% unless searching? %>
|
10
|
+
<strong>
|
11
|
+
<%= t('.no_items_yet') %>
|
12
|
+
</strong>
|
13
|
+
<% else %>
|
14
|
+
<%= t('no_results', :scope => 'refinery.admin.search') %>
|
15
|
+
<% end %>
|
16
|
+
</p>
|
17
|
+
<% end %>
|
18
|
+
</div>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(widget) -%>">
|
2
|
+
<span class='title'>
|
3
|
+
<%= widget.name %>
|
4
|
+
|
5
|
+
</span>
|
6
|
+
<span class='actions'>
|
7
|
+
|
8
|
+
<%= link_to refinery_icon_tag("application_go.png"), refinery.widgets_widget_path(widget),
|
9
|
+
:title => t('.view_live_html'),
|
10
|
+
:target => "_blank" %>
|
11
|
+
|
12
|
+
<%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_widgets_admin_widget_path(widget),
|
13
|
+
:title => t('.edit') %>
|
14
|
+
<%= link_to refinery_icon_tag("delete.png"), refinery.widgets_admin_widget_path(widget),
|
15
|
+
:class => "cancel confirm-delete",
|
16
|
+
:title => t('.delete'),
|
17
|
+
:confirm => t('message', :scope => 'refinery.admin.delete', :title => widget.name),
|
18
|
+
:method => :delete %>
|
19
|
+
</span>
|
20
|
+
</li>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'form' %>
|
@@ -0,0 +1,7 @@
|
|
1
|
+
<section id='records'>
|
2
|
+
<%= render 'records' %>
|
3
|
+
</section>
|
4
|
+
<aside id='actions'>
|
5
|
+
<%= render 'actions' %>
|
6
|
+
</aside>
|
7
|
+
<%= render '/refinery/admin/make_sortable', :tree => false if !searching? and ::Refinery::Widgets::Admin::WidgetsController.sortable? and ::Refinery::Widgets::Widget.count > 1 %>
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= render 'form' %>
|
@@ -0,0 +1,33 @@
|
|
1
|
+
<% content_for :body_content_title do %>
|
2
|
+
<%= @widget.name %>
|
3
|
+
<% end %>
|
4
|
+
|
5
|
+
<% content_for :body do %>
|
6
|
+
<section>
|
7
|
+
<h1>Name</h1>
|
8
|
+
<p>
|
9
|
+
<%=raw @widget.name %>
|
10
|
+
</p>
|
11
|
+
</section>
|
12
|
+
<section>
|
13
|
+
<h1>Content</h1>
|
14
|
+
<p>
|
15
|
+
<%=raw @widget.content %>
|
16
|
+
</p>
|
17
|
+
</section>
|
18
|
+
<% end %>
|
19
|
+
|
20
|
+
<% content_for :side_body do %>
|
21
|
+
<aside>
|
22
|
+
<h2><%= t('.other') %></h2>
|
23
|
+
<ul id="widgets">
|
24
|
+
<% @widgets.each do |widget| %>
|
25
|
+
<li>
|
26
|
+
<%= link_to widget.name, refinery.widgets_widget_path(widget) %>
|
27
|
+
</li>
|
28
|
+
<% end %>
|
29
|
+
</ul>
|
30
|
+
</aside>
|
31
|
+
<% end %>
|
32
|
+
|
33
|
+
<%= render '/refinery/content_page' %>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
en:
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
widgets:
|
5
|
+
title: Widgets
|
6
|
+
widgets:
|
7
|
+
admin:
|
8
|
+
widgets:
|
9
|
+
actions:
|
10
|
+
create_new: Add New Widget
|
11
|
+
reorder: Reorder Widgets
|
12
|
+
reorder_done: Done Reordering Widgets
|
13
|
+
records:
|
14
|
+
title: Widgets
|
15
|
+
sorry_no_results: Sorry! There are no results found.
|
16
|
+
no_items_yet: There are no Widgets yet. Click "Add New Widget" to add your first widget.
|
17
|
+
widget:
|
18
|
+
view_live_html: View this widget live <br/><em>(opens in a new window)</em>
|
19
|
+
edit: Edit this widget
|
20
|
+
delete: Remove this widget forever
|
21
|
+
widgets:
|
22
|
+
show:
|
23
|
+
other: Other Widgets
|
24
|
+
activerecord:
|
25
|
+
attributes:
|
26
|
+
'refinery/widgets/widget':
|
27
|
+
name: Name
|
28
|
+
content: Content
|
@@ -0,0 +1,29 @@
|
|
1
|
+
es:
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
widgets:
|
5
|
+
title: Widgets
|
6
|
+
# article: masculino/femenino
|
7
|
+
widgets:
|
8
|
+
admin:
|
9
|
+
widgets:
|
10
|
+
actions:
|
11
|
+
create_new: Crear nuevo widget
|
12
|
+
reorder: Reordenar widgets
|
13
|
+
reorder_done: Reordenación de widgets completada
|
14
|
+
records:
|
15
|
+
title: Widgets
|
16
|
+
sorry_no_results: Lo siento, no hay resultados
|
17
|
+
no_items_yet: No hay widgets todavía. Pulsa en "Crear nuevo Widget" para crear tu primer widget.
|
18
|
+
widget:
|
19
|
+
view_live_html: Ver este widget como abierto al público <br/><em>(abre en ventana nueva)</em>
|
20
|
+
edit: Editar este widget
|
21
|
+
delete: Borrar este widget para siempre
|
22
|
+
widgets:
|
23
|
+
show:
|
24
|
+
other: Otros widgets
|
25
|
+
activerecord:
|
26
|
+
attributes:
|
27
|
+
'refinery/widgets/widget':
|
28
|
+
name: Name
|
29
|
+
content: Content
|
@@ -0,0 +1,28 @@
|
|
1
|
+
fr:
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
widgets:
|
5
|
+
title: Widgets
|
6
|
+
widgets:
|
7
|
+
admin:
|
8
|
+
widgets:
|
9
|
+
actions:
|
10
|
+
create_new: Créer un(e) nouve(au/l/lle) Widget
|
11
|
+
reorder: Réordonner les Widgets
|
12
|
+
reorder_done: Fin de réordonnancement des Widgets
|
13
|
+
records:
|
14
|
+
title: Widgets
|
15
|
+
sorry_no_results: "Désolé ! Aucun résultat."
|
16
|
+
no_items_yet: 'Il n''y a actuellement aucun(e) Widget. Cliquer sur "Créer un(e) nouve(au/l/lle) Widget" pour créer votre premi(er/ère) widget.'
|
17
|
+
widget:
|
18
|
+
view_live_html: Voir ce(t/tte) widget <br/><em>(Ouvre une nouvelle fenêtre)</em>
|
19
|
+
edit: Modifier ce(t/tte) widget
|
20
|
+
delete: Supprimer définitivement ce(t/tte) widget
|
21
|
+
widgets:
|
22
|
+
show:
|
23
|
+
other: Autres Widgets
|
24
|
+
activerecord:
|
25
|
+
attributes:
|
26
|
+
'refinery/widgets/widget':
|
27
|
+
name: Name
|
28
|
+
content: Content
|
@@ -0,0 +1,28 @@
|
|
1
|
+
nb:
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
widgets:
|
5
|
+
title: Widgets
|
6
|
+
widgets:
|
7
|
+
admin:
|
8
|
+
widgets:
|
9
|
+
actions:
|
10
|
+
create_new: Lag en ny Widget
|
11
|
+
reorder: Endre rekkefølgen på Widgets
|
12
|
+
reorder_done: Ferdig å endre rekkefølgen Widgets
|
13
|
+
records:
|
14
|
+
title: Widgets
|
15
|
+
sorry_no_results: Beklager! Vi fant ikke noen resultater.
|
16
|
+
no_items_yet: Det er ingen Widgets enda. Klikk på "Lag en ny Widget" for å legge til din første widget.
|
17
|
+
widget:
|
18
|
+
view_live_html: Vis hvordan denne widget ser ut offentlig <br/><em>(åpner i et nytt vindu)</em>
|
19
|
+
edit: Rediger denne widget
|
20
|
+
delete: Fjern denne widget permanent
|
21
|
+
widgets:
|
22
|
+
show:
|
23
|
+
other: Andre Widgets
|
24
|
+
activerecord:
|
25
|
+
attributes:
|
26
|
+
'refinery/widgets/widget':
|
27
|
+
name: Name
|
28
|
+
content: Content
|
@@ -0,0 +1,28 @@
|
|
1
|
+
nl:
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
widgets:
|
5
|
+
title: Widgets
|
6
|
+
widgets:
|
7
|
+
admin:
|
8
|
+
widgets:
|
9
|
+
actions:
|
10
|
+
create_new: Maak een nieuwe Widget
|
11
|
+
reorder: Wijzig de volgorde van de Widgets
|
12
|
+
reorder_done: Klaar met het wijzingen van de volgorde van de Widgets
|
13
|
+
records:
|
14
|
+
title: Widgets
|
15
|
+
sorry_no_results: Helaas! Er zijn geen resultaten gevonden.
|
16
|
+
no_items_yet: Er zijn nog geen Widgets. Druk op 'Maak een nieuwe Widget' om de eerste aan te maken.
|
17
|
+
widget:
|
18
|
+
view_live_html: Bekijk deze widget op de website <br/><em>(opent een nieuw venster)</em>
|
19
|
+
edit: Bewerk deze widget
|
20
|
+
delete: Verwijder deze widget voor eeuwig
|
21
|
+
widgets:
|
22
|
+
show:
|
23
|
+
other: Andere Widgets
|
24
|
+
activerecord:
|
25
|
+
attributes:
|
26
|
+
'refinery/widgets/widget':
|
27
|
+
name: Name
|
28
|
+
content: Content
|
@@ -0,0 +1,28 @@
|
|
1
|
+
sk:
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
widgets:
|
5
|
+
title: Widgets
|
6
|
+
widgets:
|
7
|
+
admin:
|
8
|
+
widgets:
|
9
|
+
actions:
|
10
|
+
create_new: Pridať Widget
|
11
|
+
reorder: Preusporiadať Widgets
|
12
|
+
reorder_done: Koniec radenia Widgets
|
13
|
+
records:
|
14
|
+
title: Widgets
|
15
|
+
sorry_no_results: Ľutujeme, ale neboli nájdené žiadne výsledky.
|
16
|
+
no_items_yet: Nie sú vytvorené žiadne Widgets. Kliknite na "Pridať Widget" pre pridanie prvého widget.
|
17
|
+
widget:
|
18
|
+
view_live_html: Zobraziť náhľad widget<br/><em>(otvorí sa v novom okne)</em>
|
19
|
+
edit: Upraviť widget
|
20
|
+
delete: Zmazať widget
|
21
|
+
widgets:
|
22
|
+
show:
|
23
|
+
other: Daľšie Widgets
|
24
|
+
activerecord:
|
25
|
+
attributes:
|
26
|
+
'refinery/widgets/widget':
|
27
|
+
name: Name
|
28
|
+
content: Content
|
@@ -0,0 +1,30 @@
|
|
1
|
+
zh-CN:
|
2
|
+
refinery:
|
3
|
+
plugins:
|
4
|
+
widgets:
|
5
|
+
title: Widgets
|
6
|
+
widgets:
|
7
|
+
admin:
|
8
|
+
widgets:
|
9
|
+
actions:
|
10
|
+
create_new: 建立新的 Widget
|
11
|
+
reorder: 对 Widgets 重新排序
|
12
|
+
reorder_done: 对 Widgets 的重新排序结束
|
13
|
+
records:
|
14
|
+
title: Widgets
|
15
|
+
sorry_no_results: 对不起,未找到结果。 #Sorry! There are no results found.
|
16
|
+
|
17
|
+
# There are no Widgets yet. Click "Add New Widget" to add your first widget.
|
18
|
+
no_items_yet: 目前没有 Widgets . 点击 "Add New Widget" 创建一个widget.
|
19
|
+
widget:
|
20
|
+
view_live_html: 查看 widget 的最新内容.<br/><em>(新窗口中打开)</em>
|
21
|
+
edit: 编辑 widget
|
22
|
+
delete: 永久删除 widget
|
23
|
+
widgets:
|
24
|
+
show:
|
25
|
+
other: 其他 Widgets
|
26
|
+
activerecord:
|
27
|
+
attributes:
|
28
|
+
'refinery/widgets/widget':
|
29
|
+
name: Name
|
30
|
+
content: Content
|
data/config/routes.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
Refinery::Core::Engine.routes.append do
|
2
|
+
|
3
|
+
# Frontend routes
|
4
|
+
namespace :widgets do
|
5
|
+
resources :widgets, :path => '', :only => [:index, :show]
|
6
|
+
end
|
7
|
+
|
8
|
+
# Admin routes
|
9
|
+
namespace :widgets, :path => '' do
|
10
|
+
namespace :admin, :path => 'refinery' do
|
11
|
+
resources :widgets, :except => :show do
|
12
|
+
collection do
|
13
|
+
post :update_positions
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class CreateWidgetsWidgets < ActiveRecord::Migration
|
2
|
+
|
3
|
+
def up
|
4
|
+
create_table :refinery_widgets do |t|
|
5
|
+
t.string :name
|
6
|
+
t.text :content
|
7
|
+
t.integer :position
|
8
|
+
|
9
|
+
t.timestamps
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
def down
|
15
|
+
if defined?(::Refinery::UserPlugin)
|
16
|
+
::Refinery::UserPlugin.destroy_all({:name => "refinerycms-widgets"})
|
17
|
+
end
|
18
|
+
|
19
|
+
if defined?(::Refinery::Page)
|
20
|
+
::Refinery::Page.delete_all({:link_url => "/widgets/widgets"})
|
21
|
+
end
|
22
|
+
|
23
|
+
drop_table :refinery_widgets
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/db/seeds.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
(Refinery.i18n_enabled? ? Refinery::I18n.frontend_locales : [:en]).each do |lang|
|
2
|
+
I18n.locale = lang
|
3
|
+
|
4
|
+
if defined?(Refinery::User)
|
5
|
+
Refinery::User.all.each do |user|
|
6
|
+
if user.plugins.where(:name => 'refinerycms-widgets').blank?
|
7
|
+
user.plugins.create(:name => 'refinerycms-widgets',
|
8
|
+
:position => (user.plugins.maximum(:position) || -1) +1)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
url = "/widgets"
|
14
|
+
if defined?(Refinery::Page) && Refinery::Page.where(:link_url => url).empty?
|
15
|
+
page = Refinery::Page.create(
|
16
|
+
:title => 'Widgets',
|
17
|
+
:link_url => url,
|
18
|
+
:deletable => false,
|
19
|
+
:menu_match => "^#{url}(\/|\/.+?|)$"
|
20
|
+
)
|
21
|
+
Refinery::Pages.default_parts.each_with_index do |default_page_part, index|
|
22
|
+
page.parts.create(:title => default_page_part, :body => nil, :position => index)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
module Refinery
|
2
|
+
class WidgetsGenerator < Rails::Generators::Base
|
3
|
+
|
4
|
+
def rake_db
|
5
|
+
rake("refinery_widgets:install:migrations")
|
6
|
+
end
|
7
|
+
|
8
|
+
def append_load_seed_data
|
9
|
+
create_file 'db/seeds.rb' unless File.exists?(File.join(destination_root, 'db', 'seeds.rb'))
|
10
|
+
append_file 'db/seeds.rb', :verbose => true do
|
11
|
+
<<-EOH
|
12
|
+
|
13
|
+
# Added by Refinery CMS Widgets extension
|
14
|
+
Refinery::Widgets::Engine.load_seed
|
15
|
+
EOH
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'refinerycms-core'
|
2
|
+
require 'refinery/widgets/middleware'
|
3
|
+
|
4
|
+
module Refinery
|
5
|
+
autoload :WidgetsGenerator, 'generators/refinery/widgets_generator'
|
6
|
+
|
7
|
+
module Widgets
|
8
|
+
require 'refinery/widgets/engine'
|
9
|
+
WIDGET_REGEXP = /\<widget\b[^>]*\>\<\/widget\>/
|
10
|
+
|
11
|
+
class << self
|
12
|
+
attr_writer :root
|
13
|
+
|
14
|
+
def root
|
15
|
+
@root ||= Pathname.new(File.expand_path('../../../', __FILE__))
|
16
|
+
end
|
17
|
+
|
18
|
+
def factory_paths
|
19
|
+
@factory_paths ||= [ root.join('spec', 'factories').to_s ]
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Widgets
|
3
|
+
class Engine < Rails::Engine
|
4
|
+
include Refinery::Engine
|
5
|
+
isolate_namespace Refinery::Widgets
|
6
|
+
|
7
|
+
engine_name :refinery_widgets
|
8
|
+
|
9
|
+
initializer "register refinerycms_widgets plugin" do
|
10
|
+
Refinery::Plugin.register do |plugin|
|
11
|
+
plugin.name = "widgets"
|
12
|
+
plugin.url = proc { Refinery::Core::Engine.routes.url_helpers.widgets_admin_widgets_path }
|
13
|
+
plugin.pathname = root
|
14
|
+
plugin.activity = {
|
15
|
+
:class_name => :'refinery/widgets/widget',
|
16
|
+
:title => 'name'
|
17
|
+
}
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
config.after_initialize do
|
23
|
+
Refinery.register_extension(Refinery::Widgets)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,35 @@
|
|
1
|
+
module Refinery
|
2
|
+
module Widgets
|
3
|
+
class Middleware
|
4
|
+
def initialize(app)
|
5
|
+
@app = app
|
6
|
+
end
|
7
|
+
WIDGET_REGEXP = /\<widget\b[^>]*\>\<\/widget\>/
|
8
|
+
|
9
|
+
def call(env)
|
10
|
+
@status, @headers, @response = @app.call(env)
|
11
|
+
widgetize(@response)
|
12
|
+
[@status, @headers, @response]
|
13
|
+
end
|
14
|
+
|
15
|
+
def widgetize(response)
|
16
|
+
response.each do |r|
|
17
|
+
r.scan(WIDGET_REGEXP).each do |found|
|
18
|
+
# first get the name of the widget
|
19
|
+
widget_name = found.scan(/name\s*=\s*[\'\"](.*?)[\'\"]/).flatten[0]
|
20
|
+
# then find the widget
|
21
|
+
widget = Refinery::Widgets::Widget.where(name: widget_name).first
|
22
|
+
widget_content = if widget
|
23
|
+
widget.content
|
24
|
+
else
|
25
|
+
"<!-- missing widget: #{widget_name} -->"
|
26
|
+
end
|
27
|
+
# now replace the widget
|
28
|
+
r.gsub!(found, widget_content)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
response
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
require 'refinery/widgets'
|
data/readme.md
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
# Widgets extension for Refinery CMS.
|
2
|
+
|
3
|
+
## How does it work?
|
4
|
+
|
5
|
+
You make an HTML widget on the a widgets tab of your admin.
|
6
|
+
|
7
|
+
### Hurray - I have a widget now what?
|
8
|
+
|
9
|
+
Now in your pages or other HTML You can use the HTML tag
|
10
|
+
|
11
|
+
<widget name="widget-name-here"></widget>
|
12
|
+
|
13
|
+
During render, your widget tag gets replaced by whatever is in the widget-name-here widget.
|
14
|
+
|
15
|
+
Table of Contents for large sections of your page? Custom side bars on certain sections?
|
16
|
+
|
17
|
+
If this is TOO MUCH for you consider the [refinerycms-copywriting](https://github.com/unixcharles/refinerycms-copywriting) gem.
|
18
|
+
|
19
|
+
## Requirements:
|
20
|
+
Refinery CMS 2.0 or higher
|
21
|
+
|
22
|
+
## Install the widgets gem
|
23
|
+
In your gemfile include:
|
24
|
+
|
25
|
+
gem "refinerycms-widgets"
|
26
|
+
|
27
|
+
Now on the command line install your gem with bundle, and generate the widgets extension into your app.
|
28
|
+
|
29
|
+
bundle install
|
30
|
+
rails generate refinery:widgets
|
31
|
+
|
32
|
+
## Configuration changes needed
|
33
|
+
We have to allow the widget tag in the WYM editor. RefineryCMS has an config option for us.
|
34
|
+
|
35
|
+
In your config directory go to initializers/refinery/core.rb and make sure your config for wymeditor_whitelist_tags has this value for widget.
|
36
|
+
|
37
|
+
config.wymeditor_whitelist_tags = {
|
38
|
+
"widget" => { "attributes" => ["name"] }
|
39
|
+
}
|
40
|
+
|
41
|
+
note: this sometimes requires a rake assets:clean task run to clear out old JS.
|
42
|
+
|
43
|
+
Now we need to add some middleware: in config/application.rb
|
44
|
+
|
45
|
+
config.middleware.use("Refinery::Widgets::Middleware")
|
46
|
+
|
47
|
+
## TODO
|
48
|
+
* Widget caching
|
metadata
ADDED
@@ -0,0 +1,107 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: refinerycms-widgets
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Chris Reister (chrisftw)
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-22 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: refinerycms-core
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.0.0
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: 2.0.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: refinerycms-testing
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.0.9
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.0.9
|
46
|
+
description: Ruby on Rails Widgets extension for Refinery CMS
|
47
|
+
email: creister@enmasse.com
|
48
|
+
executables: []
|
49
|
+
extensions: []
|
50
|
+
extra_rdoc_files: []
|
51
|
+
files:
|
52
|
+
- app/controllers/refinery/widgets/admin/widgets_controller.rb
|
53
|
+
- app/controllers/refinery/widgets/widgets_controller.rb
|
54
|
+
- app/models/refinery/widgets/widget.rb
|
55
|
+
- app/views/refinery/widgets/admin/widgets/_actions.html.erb
|
56
|
+
- app/views/refinery/widgets/admin/widgets/_form.html.erb
|
57
|
+
- app/views/refinery/widgets/admin/widgets/_records.html.erb
|
58
|
+
- app/views/refinery/widgets/admin/widgets/_sortable_list.html.erb
|
59
|
+
- app/views/refinery/widgets/admin/widgets/_widget.html.erb
|
60
|
+
- app/views/refinery/widgets/admin/widgets/_widgets.html.erb
|
61
|
+
- app/views/refinery/widgets/admin/widgets/edit.html.erb
|
62
|
+
- app/views/refinery/widgets/admin/widgets/index.html.erb
|
63
|
+
- app/views/refinery/widgets/admin/widgets/new.html.erb
|
64
|
+
- app/views/refinery/widgets/widgets/index.html.erb
|
65
|
+
- app/views/refinery/widgets/widgets/show.html.erb
|
66
|
+
- config/locales/en.yml
|
67
|
+
- config/locales/es.yml
|
68
|
+
- config/locales/fr.yml
|
69
|
+
- config/locales/nb.yml
|
70
|
+
- config/locales/nl.yml
|
71
|
+
- config/locales/sk.yml
|
72
|
+
- config/locales/zh-CN.yml
|
73
|
+
- config/routes.rb
|
74
|
+
- db/migrate/1_create_widgets_widgets.rb
|
75
|
+
- db/seeds.rb
|
76
|
+
- lib/generators/refinery/widgets_generator.rb
|
77
|
+
- lib/refinery/widgets/engine.rb
|
78
|
+
- lib/refinery/widgets/middleware.rb
|
79
|
+
- lib/refinery/widgets.rb
|
80
|
+
- lib/refinerycms-widgets.rb
|
81
|
+
- lib/tasks/refinery/widgets.rake
|
82
|
+
- readme.md
|
83
|
+
homepage: https://github.com/enmasse-entertainment/refinerycms-widgets
|
84
|
+
licenses: []
|
85
|
+
post_install_message:
|
86
|
+
rdoc_options: []
|
87
|
+
require_paths:
|
88
|
+
- lib
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
90
|
+
none: false
|
91
|
+
requirements:
|
92
|
+
- - ! '>='
|
93
|
+
- !ruby/object:Gem::Version
|
94
|
+
version: '0'
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ! '>='
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '0'
|
101
|
+
requirements: []
|
102
|
+
rubyforge_project:
|
103
|
+
rubygems_version: 1.8.24
|
104
|
+
signing_key:
|
105
|
+
specification_version: 3
|
106
|
+
summary: Widgets extension for Refinery CMS
|
107
|
+
test_files: []
|