refinerycms-copywriting 1.0.9 → 2.0.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.
Files changed (41) hide show
  1. data/app/assets/stylesheets/refinerycms-copywriting-tab.css.scss +12 -0
  2. data/app/assets/stylesheets/refinerycms-copywriting.css.scss +3 -0
  3. data/app/controllers/refinery/copywriting/admin/phrases_controller.rb +51 -0
  4. data/app/helpers/copywriting_helper.rb +1 -1
  5. data/app/models/refinery/copywriting/phrase.rb +36 -0
  6. data/app/views/{admin/copywriting_phrases → refinery/copywriting/admin/phrases}/_actions.html.erb +0 -0
  7. data/app/views/refinery/copywriting/admin/phrases/_form.html.erb +19 -0
  8. data/app/views/{admin/copywriting_phrases → refinery/copywriting/admin/phrases}/_locale_filters.html.erb +6 -7
  9. data/app/views/refinery/copywriting/admin/phrases/_phrase.html.erb +20 -0
  10. data/app/views/refinery/copywriting/admin/phrases/_phrases.html.erb +4 -0
  11. data/app/views/refinery/copywriting/admin/phrases/_records.html.erb +15 -0
  12. data/app/views/{admin/copywriting_phrases → refinery/copywriting/admin/phrases}/_scope_filters.html.erb +6 -4
  13. data/app/views/{admin/shared/copywriting_phrases → refinery/copywriting/admin/phrases}/_value_field.html.erb +0 -0
  14. data/app/views/{admin/copywriting_phrases → refinery/copywriting/admin/phrases}/edit.html.erb +0 -0
  15. data/app/views/{admin/copywriting_phrases → refinery/copywriting/admin/phrases}/index.html.erb +3 -0
  16. data/app/views/{admin/pages → refinery/pages/admin}/tabs/_copywriting.html.erb +5 -5
  17. data/config/locales/bg.yml +18 -16
  18. data/config/locales/cs.yml +23 -0
  19. data/config/locales/en.yml +22 -19
  20. data/config/locales/es.yml +23 -0
  21. data/config/routes.rb +9 -5
  22. data/db/migrate/1_create_copywritings.rb +1 -3
  23. data/db/migrate/2_create_copywriting_translation_table.rb +32 -6
  24. data/db/migrate/4_add_refinery_prefix_to_tables.rb +13 -0
  25. data/db/migrate/5_add_phrase_last_access_at.rb +11 -0
  26. data/db/seeds/copywritings.rb +2 -2
  27. data/features/step_definitions/copywriting_steps.rb +4 -4
  28. data/lib/generators/refinery/copywriting/copywriting_generator.rb +19 -0
  29. data/lib/refinery/copywriting.rb +19 -0
  30. data/lib/refinery/copywriting/engine.rb +46 -0
  31. data/lib/refinerycms-copywriting.rb +1 -39
  32. data/spec/helpers/copywriting_helper_spec.rb +4 -4
  33. data/spec/models/copywriting_phrase_spec.rb +16 -16
  34. metadata +43 -53
  35. data/app/controllers/admin/copywriting_phrases_controller.rb +0 -46
  36. data/app/models/copywriting_phrase.rb +0 -30
  37. data/app/views/admin/copywriting_phrases/_copywriting_phrases.html.erb +0 -4
  38. data/app/views/admin/copywriting_phrases/_form.html.erb +0 -18
  39. data/app/views/admin/copywriting_phrases/_phrase.html.erb +0 -20
  40. data/app/views/admin/copywriting_phrases/_records.html.erb +0 -15
  41. data/lib/generators/refinerycms_copywriting_generator.rb +0 -6
@@ -0,0 +1,12 @@
1
+ #copywriting-tab {
2
+ ul {
3
+ padding: 0 5px 10px 10px;
4
+ }
5
+
6
+ p {
7
+ text-align: center;
8
+ font-weight: bold;
9
+ font-size: 2em;
10
+ padding: 10px 10px 10px 10px;
11
+ }
12
+ }
@@ -0,0 +1,3 @@
1
+ .scope_icon {
2
+ background-image: url("/assets/refinery/icons/zoom.png");
3
+ }
@@ -0,0 +1,51 @@
1
+ module Refinery
2
+ module Copywriting
3
+ module Admin
4
+ class PhrasesController < ::Refinery::AdminController
5
+ before_filter :find_all_locales, :find_locale, :find_scope, :find_all_scopes
6
+
7
+ crudify :'refinery/copywriting/phrase', :searchable => false,
8
+ :title_attribute => 'name', :xhr_paging => true, :sortable => false,
9
+ :redirect_to_url => 'refinery.copywriting_admin_phrases_path'
10
+
11
+ protected
12
+
13
+ def find_all_phrases
14
+ @phrases = Phrase.where(:page_id => nil)
15
+
16
+ if find_scope
17
+ @phrases = @phrases.where(:scope => find_scope)
18
+ end
19
+ end
20
+
21
+ def find_locale
22
+ @current_locale ||= (params[:switch_locale].try(:to_sym) || Thread.current[:globalize_locale] || default_locale).to_sym
23
+ end
24
+
25
+ def find_all_locales
26
+ @locales ||= ::Refinery::I18n.frontend_locales
27
+ end
28
+
29
+ def find_scope
30
+ @scope ||= params[:filter_scope]
31
+ end
32
+
33
+ def find_all_scopes
34
+ @scopes ||= Phrase.select(:scope).where(:page_id => nil).map(&:scope).uniq
35
+ end
36
+
37
+ def default_locale
38
+ ::Refinery::I18n.default_frontend_locale
39
+ end
40
+
41
+ def globalize!
42
+ super
43
+ if params[:switch_locale]
44
+ Thread.current[:globalize_locale] = (params[:switch_locale] || default_locale).try(:to_sym)
45
+ end
46
+ end
47
+
48
+ end
49
+ end
50
+ end
51
+ end
@@ -4,7 +4,7 @@ module CopywritingHelper
4
4
  options = @copywriting_options.merge(options) if @copywriting_options
5
5
  options[:default] = block_given? ? capture(&block) : options[:default]
6
6
 
7
- result = ::CopywritingPhrase.for(name, options)
7
+ result = ::Refinery::Copywriting::Phrase.for(name, options)
8
8
  end
9
9
 
10
10
  def copywriting_options(options, &block)
@@ -0,0 +1,36 @@
1
+ module Refinery
2
+ module Copywriting
3
+ class Phrase < ActiveRecord::Base
4
+
5
+ belongs_to :page, :class_name => 'Refinery::Page'
6
+ translates :value if self.respond_to?(:translates)
7
+ validates :name, :presence => true
8
+
9
+ attr_accessible :locale, :name, :default, :value, :scope, :page, :page_id, :phrase_type
10
+
11
+ if self.respond_to?(:translation_class)
12
+ self.translation_class.send :attr_accessible, :locale
13
+ end
14
+
15
+ default_scope order([:scope, :name])
16
+
17
+ def self.for(name, options = {})
18
+ options = {:phrase_type => 'text', :scope => 'default'}.merge(options.reject {|k,v| v.blank? })
19
+ options[:name] = name.to_s
20
+ options[:page_id] ||= options[:page].try(:id)
21
+
22
+ phrase = self.find_by_name_and_page_id(options[:name], options[:page_id]) || self.create(options)
23
+ phrase.update_attributes(options.except(:value, :page, :page_id, :locale))
24
+ phrase.last_access_at = Date.today
25
+ phrase.save if phrase.changed?
26
+
27
+ phrase.default_or_value
28
+ end
29
+
30
+ def default_or_value
31
+ value.present? ? value : default
32
+ end
33
+
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,19 @@
1
+ <%= form_for [refinery, :copywriting, :admin, @phrase] do |f| -%>
2
+ <%= hidden_field_tag :switch_locale, @current_locale %>
3
+
4
+ <%= render :partial => "/refinery/admin/error_messages", :locals => {
5
+ :object => @phrase,
6
+ :include_object_name => true
7
+ } %>
8
+
9
+ <%= render :partial => '/refinery/copywriting/admin/phrases/value_field', :locals => {:f => f} %>
10
+
11
+ <%= render :partial => "/refinery/admin/form_actions",
12
+ :locals => {
13
+ :f => f,
14
+ :continue_editing => false,
15
+ :hide_cancel => true,
16
+ :delete_title => t('delete', :scope => 'refinery.copywriting.admin.phrases.phrase'),
17
+ :delete_confirmation => t('message', :scope => 'refinery.admin.delete', :title => @phrase.name)
18
+ } %>
19
+ <% end -%>
@@ -1,4 +1,4 @@
1
- <% if defined?(::Refinery::I18n) and ::Refinery::I18n.enabled? %>
1
+ <% if ::Refinery.i18n_enabled? and !(::Refinery::I18n.frontend_locales == [::Refinery::I18n.default_frontend_locale]) %>
2
2
  <% locales = ::Refinery::I18n.locales.reject {|locale, title| !@locales.include?( locale ) } %>
3
3
  <ul class='collapsible_menu closed'>
4
4
 
@@ -6,21 +6,20 @@
6
6
  <% current_locale = @current_locale %>
7
7
  <% current_locale_title = locales[current_locale] %>
8
8
  <li>
9
- <%= link_to "#", :style => "background-image: url('/images/refinery/icons/flags/#{current_locale}.png');" do %>
10
- <%= current_locale_title.respond_to?(:force_encoding) ?
9
+ <%= link_to "#", :style => "background-image: url('#{asset_path "refinery/icons/flags/#{current_locale}.png"}');" do %>
10
+ <%= current_locale_title.respond_to?(:force_encoding) ?
11
11
  current_locale_title.force_encoding('utf-8') : current_locale_title %>
12
12
  <span><%= t('.change_language') %></span>
13
- <span style='display:none;'><%= t('cancel', :scope => 'shared.admin.form_actions') %></span>
13
+ <span style='display:none;'><%= t('cancel', :scope => 'refinery.admin.form_actions') %></span>
14
14
  <% end %>
15
15
  </li>
16
16
  <% end %>
17
17
 
18
18
  <% locales.sort_by{|key, value| value}.each do |locale, locale_title| %>
19
19
  <li>
20
- <%= link_to locale_title, params.dup.tap { |p| p[:switch_locale] = locale },
21
- :style => "background-image: url('/images/refinery/icons/flags/#{locale}.png');" %>
20
+ <%= link_to locale_title, refinery.copywriting_admin_phrases_path(:switch_locale => locale),
21
+ :style => "background-image: url('#{asset_path "refinery/icons/flags/#{locale}.png"}');" %>
22
22
  </li>
23
23
  <% end %>
24
24
  </ul>
25
-
26
25
  <% end %>
@@ -0,0 +1,20 @@
1
+ <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(phrase) -%>">
2
+ <span class='title'>
3
+ <% if @scope.nil? and phrase.scope %>
4
+ <%= link_to phrase.scope.capitalize, refinery.copywriting_admin_phrases_path(:filter_scope => phrase.scope) %>
5
+ <% end %>
6
+ <b><%= phrase.name %></b>
7
+ <span class="preview">- <%= truncate(phrase.default_or_value, :length => 40) %></span>
8
+ </span>
9
+ <span class='actions'>
10
+ <%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_copywriting_admin_phrase_path(phrase, :dialog => true, :switch_locale => @current_locale, :height => 620),
11
+ :title => t('.edit') %>
12
+
13
+ <%= link_to refinery_icon_tag("delete.png"), refinery.copywriting_admin_phrase_path(phrase),
14
+ :title => t('.delete'),
15
+ :class => "cancel confirm-delete",
16
+ :confirm => t('message', :scope => 'refinery.admin.delete', :title => phrase.name.capitalize),
17
+ :method => :delete %>
18
+
19
+ </span>
20
+ </li>
@@ -0,0 +1,4 @@
1
+ <%= will_paginate @phrases %>
2
+ <ul id='phrases'>
3
+ <%= render :partial => 'refinery/copywriting/admin/phrases/phrase', :collection => @phrases %>
4
+ </ul>
@@ -0,0 +1,15 @@
1
+ <div class='pagination_container'>
2
+ <% if @phrases.any? %>
3
+ <%= render 'phrases' %>
4
+ <% else %>
5
+ <p>
6
+ <% unless searching? %>
7
+ <strong>
8
+ <%= t('.no_items_yet') %>
9
+ </strong>
10
+ <% else %>
11
+ <%= t('no_results', :scope => 'refinery.admin.search') %>
12
+ <% end %>
13
+ </p>
14
+ <% end %>
15
+ </div>
@@ -1,16 +1,18 @@
1
+ <% if @scopes.any? %>
1
2
  <ul class='collapsible_menu closed'>
2
3
  <li>
3
4
  <% title = @scope ? t('.filtered_by', :filter_scope => @scope.capitalize) : t('.filter_by_scope') %>
4
- <%= link_to title, '#', :style => 'background-image: url(\'/images/refinery/icons/zoom.png\');' %>
5
+ <%= link_to title, '#', :class => 'scope_icon' %>
5
6
  </li>
6
7
  <% if @scope %>
7
8
  <li>
8
- <%= link_to t('.clear_scope_filter'), params.dup.tap { |p| p[:filter_scope] = nil } %>
9
+ <%= link_to t('.clear_scope_filter'), refinery.copywriting_admin_phrases_path %>
9
10
  </li>
10
11
  <% end %>
11
12
  <% (@scopes - [@scope]).each do |s| %>
12
13
  <li class='<%= s == @scope ? 'selected' : 'closed' %>'>
13
- <%= link_to s.capitalize, params.dup.tap { |p| p[:filter_scope] = s } %>
14
+ <%= link_to s.capitalize, refinery.copywriting_admin_phrases_path(:filter_scope => s) %>
14
15
  </li>
15
16
  <% end %>
16
- </ul>
17
+ </ul>
18
+ <% end %>
@@ -5,3 +5,6 @@
5
5
  <%= render :partial => 'actions' %>
6
6
  </aside>
7
7
 
8
+ <% content_for :stylesheets do %>
9
+ <%= stylesheet_link_tag 'refinerycms-copywriting' %>
10
+ <% end %>
@@ -1,22 +1,22 @@
1
1
  <% copywriting_phrases = @page.copywriting_phrases %>
2
2
  <% if copywriting_phrases and copywriting_phrases.any? %>
3
- <div class='wym_skin_refinery page_part' id='copywritting-tab'>
3
+ <div class='wym_skin_refinery page_part' id='copywriting-tab'>
4
4
  <ul>
5
5
  <% copywriting_phrases.each do |phrase| %>
6
6
  <li>
7
- <% f.fields_for :copywriting_phrases, phrase do |p| %>
8
- <%= render :partial => '/admin/shared/copywriting_phrases/value_field', :locals => {:f => p} %>
7
+ <%= f.fields_for :copywriting_phrases, phrase do |p| %>
8
+ <%= render :partial => 'refinery/copywriting/admin/phrases/value_field', :locals => {:f => p} %>
9
9
  <% end %>
10
10
  </li>
11
11
  <% end %>
12
12
  </ul>
13
13
  </div>
14
14
  <% else %>
15
- <div class='wym_skin_refinery page_part' id='copywritting-tab'>
15
+ <div class='wym_skin_refinery page_part' id='copywriting-tab'>
16
16
  <p><%= t('.no_copywriting_yet') %></p>
17
17
  </div>
18
18
  <% end %>
19
19
 
20
20
  <% content_for :stylesheets do %>
21
- <%= stylesheet_link_tag 'refinerycms-copywritting-tab' %>
21
+ <%= stylesheet_link_tag 'refinerycms-copywriting-tab' %>
22
22
  <% end %>
@@ -1,20 +1,22 @@
1
1
  bg:
2
- plugins:
3
- refinerycms_copywriting:
4
- title: Копирайтинг
5
- admin:
6
- copywriting_phrases:
7
- locale_filters:
8
- change_language: Смяна на език
9
- scope_filters:
10
- filter_by_scope: Филтриране по обхват
11
- filtered_by: "Филтрирано по '%{filter_scope}'"
12
- clear_scope_filter: Изчистване
13
- records:
14
- no_items_yet: Все още няма фрази.
15
- phrase:
16
- edit: Редактиране на тази фраза
17
- delete: Изтриване на тази фраза
2
+ refinery:
3
+ plugins:
4
+ refinerycms_copywriting:
5
+ title: Копирайтинг
6
+ copywriting:
7
+ admin:
8
+ phrases:
9
+ locale_filters:
10
+ change_language: Смяна на език
11
+ scope_filters:
12
+ filter_by_scope: Филтриране по обхват
13
+ filtered_by: "Филтрирано по '%{filter_scope}'"
14
+ clear_scope_filter: Изчистване
15
+ records:
16
+ no_items_yet: Все още няма фрази.
17
+ phrase:
18
+ edit: Редактиране на тази фраза
19
+ delete: Изтриване на тази фраза
18
20
  pages:
19
21
  tabs:
20
22
  copywriting:
@@ -0,0 +1,23 @@
1
+ cs:
2
+ refinery:
3
+ plugins:
4
+ refinerycms_copywriting:
5
+ title: Copywriting
6
+ copywriting:
7
+ admin:
8
+ phrases:
9
+ locale_filters:
10
+ change_language: Změnit jazyk
11
+ scope_filters:
12
+ filter_by_scope: Třídit podle umístění
13
+ filtered_by: "Třízeno podle '%{filter_scope}'"
14
+ clear_scope_filter: Zrušit
15
+ records:
16
+ no_items_yet: Žádné fráze
17
+ phrase:
18
+ edit: Upravit tuto frázi
19
+ delete: Odstranit tuto frázi
20
+ pages:
21
+ tabs:
22
+ copywriting:
23
+ no_copywriting_yet: Žádné fráze pro tuto stránku
@@ -1,21 +1,24 @@
1
1
  en:
2
- plugins:
3
- refinerycms_copywriting:
4
- title: Copywriting
5
- admin:
6
- copywriting_phrases:
7
- locale_filters:
8
- change_language: Change language
9
- scope_filters:
10
- filter_by_scope: Filter by scope
11
- filtered_by: "Filtered by '%{filter_scope}'"
12
- clear_scope_filter: Clear
13
- records:
14
- no_items_yet: There are no Phrase yet.
15
- phrase:
16
- edit: Edit this phrase
17
- delete: Remove this phrase
2
+ refinery:
3
+ plugins:
4
+ refinerycms_copywriting:
5
+ title: Copywriting
6
+ copywriting:
7
+ admin:
8
+ phrases:
9
+ locale_filters:
10
+ change_language: Change language
11
+ scope_filters:
12
+ filter_by_scope: Filter by scope
13
+ filtered_by: "Filtered by '%{filter_scope}'"
14
+ clear_scope_filter: Clear
15
+ records:
16
+ no_items_yet: There are no copywriting phrases yet.
17
+ phrase:
18
+ edit: Edit this phrase
19
+ delete: Remove this phrase
18
20
  pages:
19
- tabs:
20
- copywriting:
21
- no_copywriting_yet: No copywriting for this page
21
+ admin:
22
+ tabs:
23
+ copywriting:
24
+ no_copywriting_yet: No copywriting for this page
@@ -0,0 +1,23 @@
1
+ es:
2
+ refinery:
3
+ plugins:
4
+ refinerycms_copywriting:
5
+ title: Redacción
6
+ copywriting:
7
+ admin:
8
+ phrases:
9
+ locale_filters:
10
+ change_language: Cambiar Lenguaje
11
+ scope_filters:
12
+ filter_by_scope: Filtrar por alcanze
13
+ filtered_by: "Filtrar por '%{filter_scope}'"
14
+ clear_scope_filter: Clear
15
+ records:
16
+ no_items_yet: Todavía no hay frases.
17
+ phrase:
18
+ edit: Editar esta frase.
19
+ delete: Borrar esta frase.
20
+ pages:
21
+ tabs:
22
+ copywriting:
23
+ no_copywriting_yet: No hay redacción para esta frase.
data/config/routes.rb CHANGED
@@ -1,8 +1,12 @@
1
- Refinery::Application.routes.draw do
2
- scope(:path => 'refinery', :as => 'admin', :module => 'admin') do
3
- resources :copywriting_phrases, :path => 'copywriting', :except => [:show, :new, :create] do
4
- collection do
5
- post :update_positions
1
+ Refinery::Core::Engine.routes.draw do
2
+ namespace :copywriting, :path => '' do
3
+ namespace :admin, :path => 'refinery' do
4
+ scope :path => 'copywriting' do
5
+ resources :phrases, :except => [:show, :new, :create] do
6
+ collection do
7
+ post :update_positions
8
+ end
9
+ end
6
10
  end
7
11
  end
8
12
  end
@@ -12,12 +12,10 @@ class CreateCopywritings < ActiveRecord::Migration
12
12
  end
13
13
 
14
14
  add_index :copywriting_phrases, [:name, :scope]
15
-
16
- load(Rails.root.join('db', 'seeds', 'copywritings.rb'))
17
15
  end
18
16
 
19
17
  def self.down
20
- UserPlugin.destroy_all({:name => "refinerycms_copywriting"})
18
+ Refinery::UserPlugin.destroy_all({:name => "refinerycms_copywriting"})
21
19
 
22
20
  drop_table :copywriting_phrases
23
21
  end
@@ -1,15 +1,41 @@
1
1
  class CreateCopywritingTranslationTable < ActiveRecord::Migration
2
2
 
3
3
  def self.up
4
- ::CopywritingPhrase.create_translation_table!({
5
- :value => :text
6
- }, {
7
- :migrate_data => true
8
- })
4
+ ::Refinery::Copywriting::Phrase.table_name = Refinery::Copywriting::Phrase.table_name.sub('refinery_', '')
5
+ ::Refinery::Copywriting::Phrase.module_eval do
6
+ has_many :translations, :foreign_key => 'copywriting_phrase_id'
7
+ end
8
+ ::Refinery::Copywriting::Phrase.translation_class.table_name = Refinery::Copywriting::Phrase.translation_class.table_name.sub('refinery_', '')
9
+
10
+ ::Refinery::Copywriting::Phrase.create_translation_table!({
11
+ :value => :text
12
+ }, {
13
+ :migrate_data => true
14
+ })
15
+
16
+ rename_column Refinery::Copywriting::Phrase.translation_class.table_name, :copywriting_phrase_id, :refinery_copywriting_phrase_id
17
+
18
+ ::Refinery::Copywriting::Phrase.table_name = "refinery_#{Refinery::Copywriting::Phrase.table_name}"
19
+ ::Refinery::Copywriting::Phrase.module_eval do
20
+ has_many :translations, :foreign_key => 'refinery_copywriting_phrase_id'
21
+ end
22
+ ::Refinery::Copywriting::Phrase.translation_class.table_name = "refinery_#{Refinery::Copywriting::Phrase.translation_class.table_name}"
9
23
  end
10
24
 
11
25
  def self.down
12
- ::CopywritingPhrase.drop_translation_table! :migrate_data => true
26
+ ::Refinery::Copywriting::Phrase.table_name = Refinery::Copywriting::Phrase.table_name.sub('refinery_', '')
27
+ ::Refinery::Copywriting::Phrase.module_eval do
28
+ has_many :translations, :foreign_key => 'refinery_copywriting_phrase_id'
29
+ end
30
+ ::Refinery::Copywriting::Phrase.translation_class.table_name = Refinery::Copywriting::Phrase.translation_class.table_name.sub('refinery_', '')
31
+
32
+ ::Refinery::Copywriting::Phrase.drop_translation_table! :migrate_data => true
33
+
34
+ ::Refinery::Copywriting::Phrase.table_name = "refinery_#{Refinery::Copywriting::Phrase.table_name}"
35
+ ::Refinery::Copywriting::Phrase.module_eval do
36
+ has_many :translations, :foreign_key => 'copywriting_phrase_id'
37
+ end
38
+ ::Refinery::Copywriting::Phrase.translation_class.table_name = "refinery_#{Refinery::Copywriting::Phrase.translation_class.table_name}"
13
39
  end
14
40
 
15
41
  end
@@ -0,0 +1,13 @@
1
+ class AddRefineryPrefixToTables < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ rename_table :copywriting_phrases, :refinery_copywriting_phrases
5
+ rename_table :copywriting_phrase_translations, :refinery_copywriting_phrase_translations
6
+ end
7
+
8
+ def self.down
9
+ rename_table :refinery_copywriting_phrases, :copywriting_phrases
10
+ rename_table :refinery_copywriting_phrase_translations, :copywriting_phrase_translations
11
+ end
12
+
13
+ end
@@ -0,0 +1,11 @@
1
+ class AddPhraseLastAccessAt < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ add_column Refinery::Copywriting::Phrase.table_name, :last_access_at, :date
5
+ end
6
+
7
+ def self.down
8
+ remove_column Refinery::Copywriting::Phrase.table_name, :last_access_at
9
+ end
10
+
11
+ end
@@ -1,6 +1,6 @@
1
- User.all.each do |user|
1
+ Refinery::User.all.each do |user|
2
2
  if user.plugins.where(:name => 'refinerycms_copywriting').blank?
3
3
  user.plugins.create(:name => 'refinerycms_copywriting',
4
4
  :position => (user.plugins.maximum(:position) || -1) +1)
5
5
  end
6
- end
6
+ end if defined?(Refinery::User)
@@ -1,14 +1,14 @@
1
1
  Given /^I have no copywritings$/ do
2
- CopywritingPhrase.delete_all
2
+ Refinery::Copywriting::Phrase.delete_all
3
3
  end
4
4
 
5
5
  Given /^I (only )?have copywritings titled "?([^\"]*)"?$/ do |only, titles|
6
- CopywritingPhrase.delete_all if only
6
+ Refinery::Copywriting::Phrase.delete_all if only
7
7
  titles.split(', ').each do |title|
8
- CopywritingPhrase.create(:name => title)
8
+ Refinery::Copywriting::Phrase.create(:name => title)
9
9
  end
10
10
  end
11
11
 
12
12
  Then /^I should have ([0-9]+) copywritings?$/ do |count|
13
- CopywritingPhrase.count.should == count.to_i
13
+ Refinery::Copywriting::Phrase.count.should == count.to_i
14
14
  end
@@ -0,0 +1,19 @@
1
+ module Refinery
2
+ class CopywritingGenerator < Rails::Generators::Base
3
+
4
+ def rake_db
5
+ rake("refinery_copywriting:install:migrations")
6
+ end
7
+
8
+ def append_load_seed_data
9
+ append_file 'db/seeds.rb', :verbose => true do
10
+ <<-EOH
11
+
12
+ # Added by RefineryCMS Copywriting engine
13
+ Refinery::Copywriting::Engine.load_seed
14
+ EOH
15
+ end
16
+ end
17
+
18
+ end
19
+ end
@@ -0,0 +1,19 @@
1
+ require 'refinerycms-core'
2
+
3
+ module Refinery
4
+ autoload :CopywritingGenerator, 'generators/refinery/copywriting/copywriting_generator'
5
+
6
+ module Copywriting
7
+ require 'refinery/copywriting/engine'
8
+
9
+ class << self
10
+ def root
11
+ @root ||= Pathname.new(File.expand_path('../../../', __FILE__))
12
+ end
13
+
14
+ def table_name_prefix
15
+ 'refinery_copywriting_'
16
+ end
17
+ end
18
+ end
19
+ end
@@ -0,0 +1,46 @@
1
+ module Refinery
2
+ module Copywriting
3
+ class Engine < Rails::Engine
4
+ include Refinery::Engine
5
+
6
+ isolate_namespace Refinery::Copywriting
7
+ engine_name :refinery_copywriting
8
+
9
+ config.autoload_paths += %W( #{config.root}/lib )
10
+
11
+ config.to_prepare do
12
+ ::Refinery::Page.module_eval do
13
+ has_many :copywriting_phrases, :dependent => :destroy, :class_name => 'Refinery::Copywriting::Phrase'
14
+ accepts_nested_attributes_for :copywriting_phrases, :allow_destroy => false
15
+ attr_accessible :copywriting_phrases_attributes
16
+ end if defined?(::Refinery::Page)
17
+ end
18
+
19
+ after_inclusion do
20
+ ::ApplicationController.helper(CopywritingHelper)
21
+ end
22
+
23
+ initializer "register refinery_copywriting plugin", :after => :set_routes_reloader do |app|
24
+ ::Refinery::Pages::Tab.register do |tab|
25
+ tab.name = 'copywriting'
26
+ tab.partial = '/refinery/pages/admin/tabs/copywriting'
27
+ end
28
+
29
+ Refinery::Plugin.register do |plugin|
30
+ plugin.pathname = root
31
+ plugin.name = 'refinerycms_copywriting'
32
+ plugin.url = {:controller => '/refinery/copywriting/admin/phrases'}
33
+ plugin.menu_match = /copywriting/
34
+ plugin.activity = {
35
+ :class_name => 'Refinery::Copywriting::Phrase',
36
+ :title => :name
37
+ }
38
+ end
39
+ end
40
+
41
+ config.after_initialize do
42
+ Refinery.register_engine(Refinery::Copywriting)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -1,39 +1 @@
1
- require 'refinerycms-base'
2
-
3
- module Refinery
4
- module Copywriting
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.to_prepare do
11
- Page.module_eval do
12
- has_many :copywriting_phrases, :dependent => :destroy
13
- accepts_nested_attributes_for :copywriting_phrases, :allow_destroy => false
14
- attr_accessible :copywriting_phrases_attributes
15
- end
16
- end
17
-
18
- config.to_prepare do
19
- ::ApplicationController.helper(CopywritingHelper)
20
- end
21
-
22
- config.after_initialize do
23
- ::Refinery::Pages::Tab.register do |tab|
24
- tab.name = 'copywriting'
25
- tab.partial = '/admin/pages/tabs/copywriting'
26
- end
27
- Refinery::Plugin.register do |plugin|
28
- plugin.name = 'refinerycms_copywriting'
29
- plugin.url = {:controller => '/admin/copywriting_phrases', :action => 'index'}
30
- plugin.menu_match = /copywriting/
31
- plugin.activity = {
32
- :class => CopywritingPhrase,
33
- :title => 'Key'
34
- }
35
- end
36
- end
37
- end
38
- end
39
- end
1
+ require 'refinery/copywriting'
@@ -18,7 +18,7 @@ describe CopywritingHelper do
18
18
 
19
19
  result = copywriting("test block") { block_text }
20
20
 
21
- pharse = CopywritingPhrase.where(:name => "test block").first
21
+ pharse = Refinery::Copywriting::Phrase.where(:name => "test block").first
22
22
  pharse.should_not be_nil
23
23
  pharse.default.should == block_text
24
24
 
@@ -30,7 +30,7 @@ describe CopywritingHelper do
30
30
  copywriting("test with default scope")
31
31
  end
32
32
 
33
- CopywritingPhrase.where(:name => "test with default scope").scope.should == 'default_scope'
33
+ Refinery::Copywriting::Phrase.where(:name => "test with default scope").scope.should == 'default_scope'
34
34
  end
35
35
 
36
36
  it "it should allow you to overwrite the default options set with copywriting_options block" do
@@ -38,7 +38,7 @@ describe CopywritingHelper do
38
38
  copywriting("test without default scope", {:scope => 'without_default_scope'})
39
39
  end
40
40
 
41
- CopywritingPhrase.where(:name => "test without default scope").scope.should == 'without_default_scope'
41
+ Refinery::Copywriting::Phrase.where(:name => "test without default scope").scope.should == 'without_default_scope'
42
42
  end
43
43
 
44
44
  it "it should clear the default options after copywriting_options block" do
@@ -47,7 +47,7 @@ describe CopywritingHelper do
47
47
  end
48
48
  copywriting("test outside default scope")
49
49
 
50
- CopywritingPhrase.where(:name => "test outside default scope").scope.should_not == 'default_scope'
50
+ Refinery::Copywriting::Phrase.where(:name => "test outside default scope").scope.should_not == 'default_scope'
51
51
  end
52
52
 
53
53
  end
@@ -1,11 +1,11 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe CopywritingPhrase do
3
+ describe Refinery::Copywriting::Phrase do
4
4
 
5
5
  context "validations" do
6
6
 
7
7
  it "rejects empty name" do
8
- copy = CopywritingPhrase.new
8
+ copy = Refinery::Copywriting::Phrase.new
9
9
  copy.save.should be_false
10
10
  end
11
11
 
@@ -14,27 +14,27 @@ describe CopywritingPhrase do
14
14
  context "for" do
15
15
 
16
16
  it "should return the default string if value is not set" do
17
- CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'default'
17
+ Refinery::Copywriting::Phrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'default'
18
18
  end
19
19
 
20
20
  it "should not duplicate copywriting phrases" do
21
- 2.times { CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default'}) }
22
- CopywritingPhrase.where(:name => 'name').count.should == 1
21
+ 2.times { Refinery::Copywriting::Phrase.for('name', {:scope => 'scope', :default => 'default'}) }
22
+ Refinery::Copywriting::Phrase.where(:name => 'name').count.should == 1
23
23
  end
24
24
 
25
25
  it "should return the string the value once its set" do
26
- CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'default'
27
- copy = CopywritingPhrase.where(:name => 'name').first
26
+ Refinery::Copywriting::Phrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'default'
27
+ copy = Refinery::Copywriting::Phrase.where(:name => 'name').first
28
28
  copy.value = 'updated!'
29
29
  copy.save
30
30
 
31
- CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'updated!'
31
+ Refinery::Copywriting::Phrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'updated!'
32
32
  end
33
33
 
34
34
  it "should save options" do
35
- CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default', :phrase_type => 'wysiwyg'})
35
+ Refinery::Copywriting::Phrase.for('name', {:scope => 'scope', :default => 'default', :phrase_type => 'wysiwyg'})
36
36
 
37
- phrase = CopywritingPhrase.where(:name => 'name').first
37
+ phrase = Refinery::Copywriting::Phrase.where(:name => 'name').first
38
38
 
39
39
  phrase.name.should == "name"
40
40
  phrase.phrase_type.should == "wysiwyg"
@@ -45,8 +45,8 @@ describe CopywritingPhrase do
45
45
 
46
46
  it "should have defaults options" do
47
47
  name = "test_defaults"
48
- CopywritingPhrase.for(name)
49
- phrase = CopywritingPhrase.where(:name => name).first
48
+ Refinery::Copywriting::Phrase.for(name)
49
+ phrase = Refinery::Copywriting::Phrase.where(:name => name).first
50
50
 
51
51
  phrase.name.should == name
52
52
  phrase.phrase_type.should == "text"
@@ -59,16 +59,16 @@ describe CopywritingPhrase do
59
59
  page = Page.create(:title => "test page")
60
60
 
61
61
  name = "test_page"
62
- CopywritingPhrase.for(name, :page => page)
63
- phrase = CopywritingPhrase.where(:name => name).first
62
+ Refinery::Copywriting::Phrase.for(name, :page => page)
63
+ phrase = Refinery::Copywriting::Phrase.where(:name => name).first
64
64
 
65
65
  phrase.page_id.should == page.id
66
66
  end
67
67
 
68
68
  it "should allow you to scope to a page_id" do
69
69
  name = "test_page_id"
70
- CopywritingPhrase.for(name, :page_id => 22)
71
- phrase = CopywritingPhrase.where(:name => name).first
70
+ Refinery::Copywriting::Phrase.for(name, :page_id => 22)
71
+ phrase = Refinery::Copywriting::Phrase.where(:name => name).first
72
72
 
73
73
  phrase.page_id.should == 22
74
74
  end
metadata CHANGED
@@ -1,56 +1,55 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-copywriting
3
- version: !ruby/object:Gem::Version
4
- hash: 5
3
+ version: !ruby/object:Gem::Version
4
+ version: 2.0.0
5
5
  prerelease:
6
- segments:
7
- - 1
8
- - 0
9
- - 9
10
- version: 1.0.9
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Charles Barbier
14
9
  - David Jones
10
+ - Philip Arndt
15
11
  autorequire:
16
12
  bindir: bin
17
13
  cert_chain: []
18
-
19
- date: 2011-07-20 00:00:00 Z
14
+ date: 2011-07-20 00:00:00.000000000 Z
20
15
  dependencies: []
21
-
22
16
  description: Extract all your strings and leave no human word behind, with i18n
23
17
  email: unixcharles@gmail.com
24
18
  executables: []
25
-
26
19
  extensions: []
27
-
28
20
  extra_rdoc_files: []
29
-
30
- files:
31
- - lib/generators/refinerycms_copywriting_generator.rb
21
+ files:
22
+ - lib/generators/refinery/copywriting/copywriting_generator.rb
23
+ - lib/refinery/copywriting/engine.rb
24
+ - lib/refinery/copywriting.rb
32
25
  - lib/refinerycms-copywriting.rb
33
26
  - lib/tasks/copywritings.rake
34
27
  - config/locales/bg.yml
28
+ - config/locales/cs.yml
35
29
  - config/locales/en.yml
30
+ - config/locales/es.yml
36
31
  - config/routes.rb
37
- - app/controllers/admin/copywriting_phrases_controller.rb
32
+ - app/assets/stylesheets/refinerycms-copywriting-tab.css.scss
33
+ - app/assets/stylesheets/refinerycms-copywriting.css.scss
34
+ - app/controllers/refinery/copywriting/admin/phrases_controller.rb
38
35
  - app/helpers/copywriting_helper.rb
39
- - app/models/copywriting_phrase.rb
40
- - app/views/admin/copywriting_phrases/_actions.html.erb
41
- - app/views/admin/copywriting_phrases/_copywriting_phrases.html.erb
42
- - app/views/admin/copywriting_phrases/_form.html.erb
43
- - app/views/admin/copywriting_phrases/_locale_filters.html.erb
44
- - app/views/admin/copywriting_phrases/_phrase.html.erb
45
- - app/views/admin/copywriting_phrases/_records.html.erb
46
- - app/views/admin/copywriting_phrases/_scope_filters.html.erb
47
- - app/views/admin/copywriting_phrases/edit.html.erb
48
- - app/views/admin/copywriting_phrases/index.html.erb
49
- - app/views/admin/pages/tabs/_copywriting.html.erb
50
- - app/views/admin/shared/copywriting_phrases/_value_field.html.erb
36
+ - app/models/refinery/copywriting/phrase.rb
37
+ - app/views/refinery/copywriting/admin/phrases/_actions.html.erb
38
+ - app/views/refinery/copywriting/admin/phrases/_form.html.erb
39
+ - app/views/refinery/copywriting/admin/phrases/_locale_filters.html.erb
40
+ - app/views/refinery/copywriting/admin/phrases/_phrase.html.erb
41
+ - app/views/refinery/copywriting/admin/phrases/_phrases.html.erb
42
+ - app/views/refinery/copywriting/admin/phrases/_records.html.erb
43
+ - app/views/refinery/copywriting/admin/phrases/_scope_filters.html.erb
44
+ - app/views/refinery/copywriting/admin/phrases/_value_field.html.erb
45
+ - app/views/refinery/copywriting/admin/phrases/edit.html.erb
46
+ - app/views/refinery/copywriting/admin/phrases/index.html.erb
47
+ - app/views/refinery/pages/admin/tabs/_copywriting.html.erb
51
48
  - db/migrate/1_create_copywritings.rb
52
49
  - db/migrate/2_create_copywriting_translation_table.rb
53
50
  - db/migrate/3_add_phrase_type.rb
51
+ - db/migrate/4_add_refinery_prefix_to_tables.rb
52
+ - db/migrate/5_add_phrase_last_access_at.rb
54
53
  - db/seeds/copywritings.rb
55
54
  - spec/helpers/copywriting_helper_spec.rb
56
55
  - spec/models/copywriting_phrase_spec.rb
@@ -59,36 +58,27 @@ files:
59
58
  - features/support/paths.rb
60
59
  homepage: http://github.com/unixcharles/refinerycms-copywriting
61
60
  licenses: []
62
-
63
61
  post_install_message:
64
62
  rdoc_options: []
65
-
66
- require_paths:
63
+ require_paths:
67
64
  - lib
68
- required_ruby_version: !ruby/object:Gem::Requirement
65
+ required_ruby_version: !ruby/object:Gem::Requirement
69
66
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
77
- required_rubygems_version: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
72
  none: false
79
- requirements:
80
- - - ">="
81
- - !ruby/object:Gem::Version
82
- hash: 3
83
- segments:
84
- - 0
85
- version: "0"
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
86
77
  requirements: []
87
-
88
78
  rubyforge_project:
89
- rubygems_version: 1.8.5
79
+ rubygems_version: 1.8.10
90
80
  signing_key:
91
81
  specification_version: 3
92
- summary: Refinery CMS engine to manage copywriting, application wide or per pages, with i18n.
82
+ summary: Refinery CMS engine to manage copywriting, application wide or per pages,
83
+ with i18n.
93
84
  test_files: []
94
-
@@ -1,46 +0,0 @@
1
- module Admin
2
- class CopywritingPhrasesController < Admin::BaseController
3
- before_filter :find_all_locales, :find_locale, :find_scope, :find_all_scopes
4
-
5
- crudify :copywriting_phrase, :searchable => false,
6
- :title_attribute => 'name', :xhr_paging => true, :sortable => false
7
-
8
- protected
9
-
10
- def find_all_copywriting_phrases
11
- @copywriting_phrases = CopywritingPhrase.where(:page_id => nil).order([:scope, :name])
12
-
13
- if find_scope
14
- @copywriting_phrases = @copywriting_phrases.where(:scope => find_scope)
15
- end
16
- end
17
-
18
- def find_locale
19
- @current_locale ||= (params[:switch_locale].try(:to_sym) || Thread.current[:globalize_locale] || default_locale).to_sym
20
- end
21
-
22
- def find_all_locales
23
- @locales ||= ::Refinery::I18n.frontend_locales
24
- end
25
-
26
- def find_scope
27
- @scope ||= params[:filter_scope]
28
- end
29
-
30
- def find_all_scopes
31
- @scopes ||= CopywritingPhrase.select(:scope).where(:page_id => nil).map(&:scope).uniq
32
- end
33
-
34
- def default_locale
35
- ::Refinery::I18n.default_frontend_locale
36
- end
37
-
38
- def globalize!
39
- super
40
- if params[:switch_locale]
41
- Thread.current[:globalize_locale] = (params[:switch_locale] || default_locale).try(:to_sym)
42
- end
43
- end
44
-
45
- end
46
- end
@@ -1,30 +0,0 @@
1
- class CopywritingPhrase < ActiveRecord::Base
2
-
3
- belongs_to :page
4
- translates :value if self.respond_to?(:translates)
5
- validates :name, :presence => true
6
-
7
- attr_accessible :locale, :name, :default, :value, :scope, :page_id, :phrase_type
8
-
9
- def self.for(name, options = {})
10
- options = {:phrase_type => 'text', :scope => 'default'}.merge(options)
11
- name = name.to_s
12
- page_id = (options[:page].try(:id) || options[:page_id] || nil)
13
-
14
- if (phrase = self.where(:name => name, :page_id => page_id).first).nil?
15
- phrase = self.create(:name => name,
16
- :scope => options[:scope],
17
- :value => options[:value],
18
- :default => options[:default],
19
- :page_id => page_id,
20
- :phrase_type => options[:phrase_type])
21
- end
22
-
23
- phrase.default_or_value
24
- end
25
-
26
- def default_or_value
27
- value.blank? ? default : value
28
- end
29
-
30
- end
@@ -1,4 +0,0 @@
1
- <%= will_paginate @copywriting_phrases %>
2
- <ul id='phrases'>
3
- <%= render :partial => 'admin/copywriting_phrases/phrase', :collection => @copywriting_phrases %>
4
- </ul>
@@ -1,18 +0,0 @@
1
- <%= form_for [:admin, @copywriting_phrase] do |f| -%>
2
- <%= hidden_field_tag :switch_locale, @current_locale %>
3
-
4
- <%= render :partial => "/shared/admin/error_messages", :locals => {
5
- :object => @copywriting_phrase,
6
- :include_object_name => true
7
- } %>
8
-
9
- <%= render :partial => '/admin/shared/copywriting_phrases/value_field', :locals => {:f => f} %>
10
-
11
- <%= render :partial => "/shared/admin/form_actions",
12
- :locals => {
13
- :f => f,
14
- :continue_editing => false,
15
- :delete_title => t('delete', :scope => 'admin.copywriting.phrase'),
16
- :delete_confirmation => t('message', :scope => 'shared.admin.delete', :title => @copywriting_phrase.name)
17
- } %>
18
- <% end -%>
@@ -1,20 +0,0 @@
1
- <li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(phrase) -%>">
2
- <span class='title'>
3
- <% if @scope.nil? and phrase.scope %>
4
- <%= link_to phrase.scope.capitalize, params.dup.tap { |p| p[:filter_scope] = phrase.scope } %>
5
- <% end %>
6
- <b><%= phrase.name %></b>
7
- <span class="preview">- <%= truncate(phrase.default_or_value, :length => 40) %></span>
8
- </span>
9
- <span class='actions'>
10
- <%= link_to refinery_icon_tag("application_edit.png"), edit_admin_copywriting_phrase_path(phrase, :dialog => true, :switch_locale => @current_locale),
11
- :title => t('.edit') %>
12
-
13
- <%= link_to refinery_icon_tag("delete.png"), admin_copywriting_phrase_path(phrase),
14
- :title => t('.delete'),
15
- :class => "cancel confirm-delete",
16
- :confirm => t('message', :scope => 'shared.admin.delete', :title => phrase.name.capitalize),
17
- :method => :delete %>
18
-
19
- </span>
20
- </li>
@@ -1,15 +0,0 @@
1
- <% if @copywriting_phrases.any? %>
2
- <div class='pagination_container'>
3
- <%= render :partial => 'copywriting_phrases', :copywriting_phrases => @copywriting_phrases %>
4
- </div>
5
- <% else %>
6
- <p>
7
- <% unless searching? %>
8
- <strong>
9
- <%= t('.no_items_yet') %>
10
- </strong>
11
- <% else %>
12
- <%= t('no_results', :scope => 'shared.admin.search') %>
13
- <% end %>
14
- </p>
15
- <% end %>
@@ -1,6 +0,0 @@
1
- class RefinerycmsCopywritingGenerator < Refinery::Generators::EngineInstaller
2
-
3
- source_root File.expand_path('../../../', __FILE__)
4
- engine_name "refinerycms_copywriting"
5
-
6
- end