refinerycms-copywriting 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,46 @@
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
@@ -0,0 +1,11 @@
1
+ module CopywritingHelper
2
+ def copywriting(name, options = {}, &block)
3
+ scope = options[:scope] || 'default'
4
+ page_id = options[:page_id] || options[:page].try(:id) || nil
5
+ default = block_given? ? capture(&block) : options[:default]
6
+
7
+ result = ::CopywritingPhrase.for(name, scope, default, page_id)
8
+ result = result.html_safe if options[:html_safe]
9
+ result
10
+ end
11
+ end
@@ -0,0 +1,31 @@
1
+ class CopywritingPhrase < ActiveRecord::Base
2
+ acts_as_indexed :fields => [:name, :default]
3
+
4
+ belongs_to :page
5
+
6
+ translates :value if self.respond_to?(:translates)
7
+
8
+ validates :name, :presence => true
9
+
10
+
11
+ attr_accessible :locale, :name, :default, :value, :scope, :page_id
12
+
13
+ def self.for(name, scope, default, page_id)
14
+ name = name.to_s.downcase
15
+ scope = scope.to_s.downcase
16
+
17
+ if phrase = self.where(:name => name).first
18
+ phrase.default_or_value
19
+ else
20
+ if phrase = self.create(:name => name, :scope => scope, :default => default, :page_id => page_id)
21
+ phrase.default
22
+ else
23
+ "<span>Copywriting error: #{phrase.to_a.join(', ')}<span>"
24
+ end
25
+ end
26
+ end
27
+
28
+ def default_or_value
29
+ value.blank? ? default : value
30
+ end
31
+ end
@@ -0,0 +1,2 @@
1
+ <%= render 'locale_filters' if defined?(::Refinery::I18n) %>
2
+ <%= render 'scope_filters' %>
@@ -0,0 +1,4 @@
1
+ <%= will_paginate @copywriting_phrases %>
2
+ <ul id='phrases'>
3
+ <%= render :partial => 'admin/copywriting_phrases/phrase', :collection => @copywriting_phrases %>
4
+ </ul>
@@ -0,0 +1,21 @@
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
+ <div class='field'>
10
+ <%= f.label :value, f.object.name.capitalize -%>
11
+ <%= f.text_area :value, :rows => 12, :class => 'widest' -%>
12
+ </div>
13
+
14
+ <%= render :partial => "/shared/admin/form_actions",
15
+ :locals => {
16
+ :f => f,
17
+ :continue_editing => false,
18
+ :delete_title => t('delete', :scope => 'admin.copywriting.phrase'),
19
+ :delete_confirmation => t('message', :scope => 'shared.admin.delete', :title => @copywriting_phrase.name)
20
+ } %>
21
+ <% end -%>
@@ -0,0 +1,26 @@
1
+ <% if defined?(::Refinery::I18n) and ::Refinery::I18n.enabled? %>
2
+ <% locales = ::Refinery::I18n.locales.reject {|locale, title| !@locales.include?( locale ) } %>
3
+ <ul class='collapsible_menu closed'>
4
+
5
+ <% if @current_locale %>
6
+ <% current_locale = @current_locale %>
7
+ <% current_locale_title = locales[current_locale] %>
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) ?
11
+ current_locale_title.force_encoding('utf-8') : current_locale_title %>
12
+ <span><%= t('.change_language') %></span>
13
+ <span style='display:none;'><%= t('cancel', :scope => 'shared.admin.form_actions') %></span>
14
+ <% end %>
15
+ </li>
16
+ <% end %>
17
+
18
+ <% locales.sort_by{|key, value| value}.each do |locale, locale_title| %>
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');" %>
22
+ </li>
23
+ <% end %>
24
+ </ul>
25
+
26
+ <% 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, 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),
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>
@@ -0,0 +1,15 @@
1
+ <% if @copywriting_phrases.any? %>
2
+ <div class='pagination_container'>
3
+ <%= render :partial => 'copywritings', :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 %>
@@ -0,0 +1,16 @@
1
+ <ul class='collapsible_menu closed'>
2
+ <li>
3
+ <% 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
+ </li>
6
+ <% if @scope %>
7
+ <li>
8
+ <%= link_to t('.clear_scope_filter'), params.dup.tap { |p| p[:filter_scope] = nil } %>
9
+ </li>
10
+ <% end %>
11
+ <% (@scopes - [@scope]).each do |s| %>
12
+ <li class='<%= s == @scope ? 'selected' : 'closed' %>'>
13
+ <%= link_to s.capitalize, params.dup.tap { |p| p[:filter_scope] = s } %>
14
+ </li>
15
+ <% end %>
16
+ </ul>
@@ -0,0 +1 @@
1
+ <%= render :partial => "form" %>
@@ -0,0 +1,7 @@
1
+ <section id='records'>
2
+ <%= render :partial => 'records' %>
3
+ </section>
4
+ <aside id='actions'>
5
+ <%= render :partial => 'actions' %>
6
+ </aside>
7
+
@@ -0,0 +1,25 @@
1
+ <% copywriting_phrases = @page.copywriting_phrases %>
2
+ <% if copywriting_phrases and copywriting_phrases.any? %>
3
+ <div class='wym_skin_refinery page_part' id='copywritting-tab'>
4
+ <ul>
5
+ <% copywriting_phrases.each do |phrase| %>
6
+ <li>
7
+ <% f.fields_for :copywriting_phrases, phrase do |p|%>
8
+ <div class='field'>
9
+ <%= p.label :value, p.object.name.capitalize -%>
10
+ <%= p.text_field :value, :class => 'widest' -%>
11
+ </div>
12
+ <% end %>
13
+ </li>
14
+ <% end %>
15
+ </ul>
16
+ </div>
17
+ <% else %>
18
+ <div class='wym_skin_refinery page_part' id='copywritting-tab'>
19
+ <p><%= t('.no_copywriting_yet') %></p>
20
+ </div>
21
+ <% end %>
22
+
23
+ <% content_for :stylesheets do %>
24
+ <%= stylesheet_link_tag 'refinerycms-copywritting-tab' %>
25
+ <% end %>
@@ -0,0 +1,21 @@
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
18
+ pages:
19
+ tabs:
20
+ copywriting:
21
+ no_copywriting_yet: No copywriting for this page
data/config/routes.rb ADDED
@@ -0,0 +1,9 @@
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
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,25 @@
1
+ class CreateCopywritings < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ create_table :copywriting_phrases do |t|
5
+ t.string :name
6
+ t.text :default
7
+ t.text :value
8
+ t.string :scope
9
+ t.integer :page_id
10
+
11
+ t.timestamps
12
+ end
13
+
14
+ add_index :copywriting_phrases, :name, :scope
15
+
16
+ load(Rails.root.join('db', 'seeds', 'copywritings.rb'))
17
+ end
18
+
19
+ def self.down
20
+ UserPlugin.destroy_all({:name => "refinerycms_copywriting"})
21
+
22
+ drop_table :copywriting_phrases
23
+ end
24
+
25
+ end
@@ -0,0 +1,16 @@
1
+ class CreateCopywritingTranslationTable < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ ::CopywritingPhrase.create_translation_table!({
5
+ :value => :string
6
+ }, {
7
+ :migrate_data => true
8
+ })
9
+ end
10
+ end
11
+
12
+ def self.down
13
+ ::CopywritingPhrase.drop_translation_table! :migrate_data => true
14
+ end
15
+
16
+ end
@@ -0,0 +1,6 @@
1
+ User.all.each do |user|
2
+ if user.plugins.where(:name => 'refinerycms_copywriting').blank?
3
+ user.plugins.create(:name => 'refinerycms_copywriting',
4
+ :position => (user.plugins.maximum(:position) || -1) +1)
5
+ end
6
+ end
@@ -0,0 +1,36 @@
1
+ @copywritings
2
+ Feature: Copywritings
3
+ In order to have copywritings on my website
4
+ As an administrator
5
+ I want to manage copywritings
6
+
7
+ Background:
8
+ Given I am a logged in refinery user
9
+ And I have no copywritings
10
+
11
+ @copywritings-list @list
12
+ Scenario: Copywritings List
13
+ Given I have copywritings titled slogan, subtitle
14
+ When I go to the list of copywritings
15
+ Then I should see "slogan"
16
+ And I should see "subtitle"
17
+
18
+ @copywritings-edit @edit
19
+ Scenario: Edit Existing Copywriting
20
+ Given I have copywritings titled "slogan"
21
+ When I go to the list of copywritings
22
+ And I follow "Edit this copywriting" within ".actions"
23
+ Then I fill in "value" with "A different slogan"
24
+ And I press "Save"
25
+ Then I should see "'slogan' was successfully updated."
26
+ And I should be on the list of copywritings
27
+ And I should see "A different slogan"
28
+
29
+ @copywritings-delete @delete
30
+ Scenario: Delete Copywriting
31
+ Given I only have copywritings titled slogan
32
+ When I go to the list of copywritings
33
+ And I follow "Remove this phrase"
34
+ Then I should see "'slogan' was successfully removed."
35
+ And I should have 0 copywritings
36
+
@@ -0,0 +1,14 @@
1
+ Given /^I have no copywritings$/ do
2
+ CopywritingPhrase.delete_all
3
+ end
4
+
5
+ Given /^I (only )?have copywritings titled "?([^\"]*)"?$/ do |only, titles|
6
+ CopywritingPhrase.delete_all if only
7
+ titles.split(', ').each do |title|
8
+ CopywritingPhrase.create(:name => title)
9
+ end
10
+ end
11
+
12
+ Then /^I should have ([0-9]+) copywritings?$/ do |count|
13
+ CopywritingPhrase.count.should == count.to_i
14
+ end
@@ -0,0 +1,14 @@
1
+ module NavigationHelpers
2
+ module Refinery
3
+ module Copywritings
4
+ def path_to(page_name)
5
+ case page_name
6
+ when /the list of copywritings/
7
+ admin_copywriting_phrases_path
8
+ else
9
+ nil
10
+ end
11
+ end
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,6 @@
1
+ class RefinerycmsCopywritingGenerator < Refinery::Generators::EngineInstaller
2
+
3
+ source_root File.expand_path('../../../', __FILE__)
4
+ engine_name "refinerycms_copywriting"
5
+
6
+ end
@@ -0,0 +1,39 @@
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
@@ -0,0 +1,13 @@
1
+ namespace :refinery do
2
+
3
+ namespace :copywriting do
4
+
5
+ # call this task my running: rake refinery:copywritings: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
@@ -0,0 +1,36 @@
1
+ require 'spec_helper'
2
+
3
+ describe CopywritingPhrase do
4
+
5
+ context "validations" do
6
+
7
+ it "rejects empty name" do
8
+ copy = CopywritingPhrase.new
9
+ copy.save.should be_false
10
+ end
11
+
12
+ end
13
+
14
+ context "for" do
15
+
16
+ it "should return the default string if value is not set" do
17
+ CopywritingPhrase.for('name', 'scope', 'default', nil).should == 'default'
18
+ end
19
+
20
+ it "should not duplicate copywriting phrases" do
21
+ 2.times { CopywritingPhrase.for('name', 'scope', 'default', nil) }
22
+ CopywritingPhrase.where(:name => 'name').count.should == 1
23
+ end
24
+
25
+ it "should return the string the value once its set" do
26
+ CopywritingPhrase.for('name', 'scope', 'default', nil).should == 'default'
27
+ copy = CopywritingPhrase.where(:name => 'name').first
28
+ copy.value = 'updated!'
29
+ copy.save
30
+
31
+ CopywritingPhrase.for('name', 'scope', 'default', nil).should == 'updated!'
32
+ end
33
+
34
+ end
35
+
36
+ end
metadata ADDED
@@ -0,0 +1,90 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: refinerycms-copywriting
3
+ version: !ruby/object:Gem::Version
4
+ hash: 15
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ version: "1.0"
10
+ platform: ruby
11
+ authors:
12
+ - Charles Barbier
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2011-05-30 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Copywriting engine for Refinery CMS
22
+ email: unixcharles@gmail.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/generators/refinerycms_copywriting_generator.rb
31
+ - lib/refinerycms-copywriting.rb
32
+ - lib/tasks/copywritings.rake
33
+ - config/locales/en.yml
34
+ - config/routes.rb
35
+ - app/controllers/admin/copywriting_phrases_controller.rb
36
+ - app/helpers/copywriting_helper.rb
37
+ - app/models/copywriting_phrase.rb
38
+ - app/views/admin/copywriting_phrases/_actions.html.erb
39
+ - app/views/admin/copywriting_phrases/_copywritings.html.erb
40
+ - app/views/admin/copywriting_phrases/_form.html.erb
41
+ - app/views/admin/copywriting_phrases/_locale_filters.html.erb
42
+ - app/views/admin/copywriting_phrases/_phrase.html.erb
43
+ - app/views/admin/copywriting_phrases/_records.html.erb
44
+ - app/views/admin/copywriting_phrases/_scope_filters.html.erb
45
+ - app/views/admin/copywriting_phrases/edit.html.erb
46
+ - app/views/admin/copywriting_phrases/index.html.erb
47
+ - app/views/admin/pages/tabs/_copywriting.html.erb
48
+ - db/migrate/1_create_copywritings.rb
49
+ - db/migrate/2_create_copywriting_translation_table.rb
50
+ - db/seeds/copywritings.rb
51
+ - spec/models/copywriting_phrase_spec.rb
52
+ - features/manage_copywriting.feature
53
+ - features/step_definitions/copywriting_steps.rb
54
+ - features/support/paths.rb
55
+ has_rdoc: true
56
+ homepage: http://github.com/unixcharles/refinerycms-copywriting
57
+ licenses: []
58
+
59
+ post_install_message:
60
+ rdoc_options: []
61
+
62
+ require_paths:
63
+ - lib
64
+ required_ruby_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ">="
77
+ - !ruby/object:Gem::Version
78
+ hash: 3
79
+ segments:
80
+ - 0
81
+ version: "0"
82
+ requirements: []
83
+
84
+ rubyforge_project:
85
+ rubygems_version: 1.6.2
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Refinery CMS engine to manage copywriting, application wide or per pages, with i18n.
89
+ test_files: []
90
+