refinerycms-copywriting 1.0.5 → 1.0.6

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.
@@ -1,11 +1,11 @@
1
1
  module CopywritingHelper
2
+
2
3
  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]
4
+ options[:default] = block_given? ? capture(&block) : options[:default]
6
5
 
7
- result = ::CopywritingPhrase.for(name, scope, default, page_id)
8
- result = result.html_safe if options[:html_safe]
9
- result
6
+ result = ::CopywritingPhrase.for(name, options)
7
+
8
+ options[:html_safe] ? result.html_safe : result
10
9
  end
10
+
11
11
  end
@@ -1,29 +1,29 @@
1
1
  class CopywritingPhrase < ActiveRecord::Base
2
- belongs_to :page
3
2
 
3
+ belongs_to :page
4
4
  translates :value if self.respond_to?(:translates)
5
-
6
5
  validates :name, :presence => true
7
-
8
6
 
9
- attr_accessible :locale, :name, :default, :value, :scope, :page_id
7
+ attr_accessible :locale, :name, :default, :value, :scope, :page_id, :phrase_type
10
8
 
11
- def self.for(name, scope, default, page_id)
12
- name = name.to_s.downcase
13
- scope = scope.to_s.downcase
9
+ def self.for(name, options = {})
10
+ options = {:phrase_type => 'text', :scope => 'default'}.merge(options)
11
+ name = name.to_s
14
12
 
15
- if phrase = self.where(:name => name).first
16
- phrase.default_or_value
17
- else
18
- if phrase = self.create(:name => name, :scope => scope, :default => default, :page_id => page_id)
19
- phrase.default
20
- else
21
- "<span>Copywriting error: #{phrase.to_a.join(', ')}<span>"
22
- end
13
+ if (phrase = self.where(:name => name).first).nil?
14
+ phrase = self.create(:name => name,
15
+ :scope => options[:scope],
16
+ :default => options[:default],
17
+ :value => options[:value],
18
+ :page_id => (options[:page].try(:id) || options[:page_id] || nil),
19
+ :phrase_type => options[:phrase_type])
23
20
  end
21
+
22
+ phrase.default_or_value
24
23
  end
25
24
 
26
25
  def default_or_value
27
26
  value.blank? ? default : value
28
27
  end
29
- end
28
+
29
+ end
@@ -5,11 +5,8 @@
5
5
  :object => @copywriting_phrase,
6
6
  :include_object_name => true
7
7
  } %>
8
-
9
- <div class='field'>
10
- <%= f.label :value, f.object.name.capitalize -%>
11
- <%= f.text_area :value, :value => f.object.default_or_value, :rows => 12, :class => 'widest' -%>
12
- </div>
8
+
9
+ <%= render :partial => '/admin/shared/copywriting_phrases/value_field', :locals => {:f => f} %>
13
10
 
14
11
  <%= render :partial => "/shared/admin/form_actions",
15
12
  :locals => {
@@ -4,11 +4,8 @@
4
4
  <ul>
5
5
  <% copywriting_phrases.each do |phrase| %>
6
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>
7
+ <% f.fields_for :copywriting_phrases, phrase do |p| %>
8
+ <%= render :partial => '/admin/shared/copywriting_phrases/value_field', :locals => {:f => p} %>
12
9
  <% end %>
13
10
  </li>
14
11
  <% end %>
@@ -0,0 +1,11 @@
1
+ <div class='field'>
2
+ <%= f.label :value, f.object.name.capitalize -%>
3
+ <% case f.object.phrase_type %>
4
+ <% when "text" %>
5
+ <%= f.text_area :value, :rows => 12, :class => 'widest' -%>
6
+ <% when "wysiwyg" %>
7
+ <%= f.text_area :value, :rows => 5, :class => 'widest wymeditor' -%>
8
+ <% else %>
9
+ <%= f.text_field :value, :class => 'widest larger' -%>
10
+ <% end %>
11
+ </div>
@@ -0,0 +1,11 @@
1
+ class AddPhraseType < ActiveRecord::Migration
2
+
3
+ def self.up
4
+ add_column :copywriting_phrases, :phrase_type, :string
5
+ end
6
+
7
+ def self.down
8
+ remove_column :copywriting_phrases, :phrase_type
9
+ end
10
+
11
+ end
@@ -0,0 +1,30 @@
1
+ require 'spec_helper'
2
+
3
+ describe CopywritingHelper do
4
+
5
+ context "usage" do
6
+
7
+ it "it should create using defaults" do
8
+ copywriting("test").should == nil
9
+ end
10
+
11
+ it "it should allow you to set options" do
12
+ copywriting("test", {:scope => 'scope', :default => 'default', :phrase_type => 'wysiwyg'}).should == 'default'
13
+ copywriting("test two", {:default => "test just default"}).should == "test just default"
14
+ end
15
+
16
+ it "it should allow you to set the value using a block" do
17
+ block_text = "this is a block"
18
+
19
+ result = copywriting("test block") { block_text }
20
+
21
+ pharse = CopywritingPhrase.where(:name => "test block").first
22
+ pharse.should_not be_nil
23
+ pharse.default.should == block_text
24
+
25
+ copywriting("test block").should == block_text
26
+ end
27
+
28
+ end
29
+
30
+ end
@@ -14,21 +14,63 @@ 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', 'default', nil).should == 'default'
17
+ CopywritingPhrase.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', 'default', nil) }
21
+ 2.times { CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default'}) }
22
22
  CopywritingPhrase.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', 'default', nil).should == 'default'
26
+ CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'default'
27
27
  copy = CopywritingPhrase.where(:name => 'name').first
28
28
  copy.value = 'updated!'
29
29
  copy.save
30
30
 
31
- CopywritingPhrase.for('name', 'scope', 'default', nil).should == 'updated!'
31
+ CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default'}).should == 'updated!'
32
+ end
33
+
34
+ it "should save options" do
35
+ CopywritingPhrase.for('name', {:scope => 'scope', :default => 'default', :phrase_type => 'wysiwyg'})
36
+
37
+ phrase = CopywritingPhrase.where(:name => 'name').first
38
+
39
+ phrase.name.should == "name"
40
+ phrase.phrase_type.should == "wysiwyg"
41
+ phrase.scope.should == "scope"
42
+ phrase.default.should == "default"
43
+ phrase.value.should == nil
44
+ end
45
+
46
+ it "should have defaults options" do
47
+ name = "test_defaults"
48
+ CopywritingPhrase.for(name)
49
+ phrase = CopywritingPhrase.where(:name => name).first
50
+
51
+ phrase.name.should == name
52
+ phrase.phrase_type.should == "text"
53
+ phrase.scope.should == "default"
54
+ phrase.default.should == nil
55
+ phrase.value.should == nil
56
+ end
57
+
58
+ it "should allow you to scope to a page" do
59
+ page = Page.create(:title => "test page")
60
+
61
+ name = "test_page"
62
+ CopywritingPhrase.for(name, :page => page)
63
+ phrase = CopywritingPhrase.where(:name => name).first
64
+
65
+ phrase.page_id.should == page.id
66
+ end
67
+
68
+ it "should allow you to scope to a page_id" do
69
+ name = "test_page_id"
70
+ CopywritingPhrase.for(name, :page_id => 22)
71
+ phrase = CopywritingPhrase.where(:name => name).first
72
+
73
+ phrase.page_id.should == 22
32
74
  end
33
75
 
34
76
  end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: refinerycms-copywriting
3
3
  version: !ruby/object:Gem::Version
4
- hash: 29
4
+ hash: 27
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 5
10
- version: 1.0.5
9
+ - 6
10
+ version: 1.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - Charles Barbier
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2011-07-04 00:00:00 Z
18
+ date: 2011-07-01 00:00:00 Z
19
19
  dependencies: []
20
20
 
21
21
  description: Extract all your strings and leave no human word behind, with i18n
@@ -45,9 +45,12 @@ files:
45
45
  - app/views/admin/copywriting_phrases/edit.html.erb
46
46
  - app/views/admin/copywriting_phrases/index.html.erb
47
47
  - app/views/admin/pages/tabs/_copywriting.html.erb
48
+ - app/views/admin/shared/copywriting_phrases/_value_field.html.erb
48
49
  - db/migrate/1_create_copywritings.rb
49
50
  - db/migrate/2_create_copywriting_translation_table.rb
51
+ - db/migrate/3_add_phrase_type.rb
50
52
  - db/seeds/copywritings.rb
53
+ - spec/helpers/copywriting_helper_spec.rb
51
54
  - spec/models/copywriting_phrase_spec.rb
52
55
  - features/manage_copywriting.feature
53
56
  - features/step_definitions/copywriting_steps.rb