seorel 0.0.1 → 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -2,13 +2,18 @@
2
2
 
3
3
  Ruby on Rails SEO Metatags plugins for ActiveRecord models
4
4
 
5
+ [![Gem Version](https://badge.fury.io/rb/seorel.png)](http://badge.fury.io/rb/seorel)
6
+
5
7
  ## Rails Setup
6
8
 
7
9
 
8
10
  `Gemfile.rb`:
9
11
 
10
12
  ```ruby
11
- gem 'seorel', github: 'dalpo/seorel'
13
+ gem 'seorel', '~> 0.0.2'
14
+
15
+ # the edge version can be had using:
16
+ # gem 'seorel', github: 'dalpo/seorel'
12
17
  ```
13
18
 
14
19
  `Console`:
@@ -33,6 +38,7 @@ Seorel.configure do |config|
33
38
  # config.default_image = nil
34
39
  # config.prepend_title = nil
35
40
  # config.append_title = nil
41
+ # config.store_seorel_if = :empty # Available values :empty | :changed
36
42
  end
37
43
  ```
38
44
 
@@ -2,14 +2,7 @@
2
2
  module Seorel
3
3
  class Seorel < ActiveRecord::Base
4
4
 
5
- belongs_to :seorelable, polymorphic: true
6
-
7
- mount_uploader :image, Seorel::ImageUploader
8
-
9
- before_save do
10
- self.title = ::ActionController::Base.helpers.strip_tags(self.title).first(255) if self.title?
11
- self.description = ::ActionController::Base.helpers.strip_tags(self.description).first(255) if self.description?
12
- end
5
+ belongs_to :seorelable, polymorphic: true, touch: true
13
6
 
14
7
  def title?
15
8
  self.title.present?
@@ -23,5 +16,9 @@ module Seorel
23
16
  I18n.t("seorel.admin.label")
24
17
  end
25
18
 
19
+ def image?
20
+ false
21
+ end
22
+
26
23
  end
27
24
  end
@@ -5,4 +5,5 @@ Seorel.configure do |config|
5
5
  # config.default_image = nil
6
6
  # config.prepend_title = nil
7
7
  # config.append_title = nil
8
+ # config.store_seorel_if = :empty # Available values :empty | :changed
8
9
  end
data/lib/seorel/config.rb CHANGED
@@ -24,6 +24,7 @@ module Seorel
24
24
  config_accessor :default_image
25
25
  config_accessor :prepend_title
26
26
  config_accessor :append_title
27
+ config_accessor :store_seorel_if
27
28
 
28
29
  def param_name
29
30
  config.param_name.respond_to?(:call) ? config.param_name.call : config.param_name
@@ -42,5 +43,6 @@ module Seorel
42
43
  config.default_image = nil
43
44
  config.prepend_title = nil
44
45
  config.append_title = nil
46
+ config.store_seorel_if = :empty
45
47
  end
46
48
  end
@@ -16,14 +16,14 @@ module Seorel
16
16
  def add_seorel_hash(values = {})
17
17
  seorel_params.title = values[:title] if values[:title].present?
18
18
  seorel_params.description = values[:description] if values[:description].present?
19
- seorel_params.image = values[:image] if values[:image].present?
19
+ # seorel_params.image = values[:image] if values[:image].present?
20
20
  seorel_params
21
21
  end
22
22
 
23
23
  def add_seorel_model(model)
24
24
  seorel_params.title = model.seo_title
25
25
  seorel_params.description = model.seo_description
26
- seorel_params.image = model.seo_image.default.url if model.seo_image?
26
+ # seorel_params.image = model.seo_image.default.url if model.seo_image?
27
27
  seorel_params
28
28
  end
29
29
 
@@ -4,7 +4,6 @@ require 'active_support/configurable'
4
4
  module Seorel
5
5
  module Controller
6
6
  class Params
7
-
8
7
  include ActiveSupport::Configurable
9
8
 
10
9
  config_accessor :title
@@ -30,7 +29,6 @@ module Seorel
30
29
  def default_options
31
30
  ::Seorel.config
32
31
  end
33
-
34
32
  end
35
33
  end
36
34
  end
data/lib/seorel/engine.rb CHANGED
@@ -8,9 +8,7 @@ module Seorel
8
8
  app.config.to_prepare do
9
9
  ActionController::Base.send :extend, ::Seorel::Controller::ClassMethods
10
10
  ActionController::Base.send :include, ::Seorel::Controller::InstanceMethods
11
-
12
11
  ActionController::Base.send :helper_method, :seorel_params
13
-
14
12
  ActionView::Base.send :include, ::Seorel::Helper
15
13
  end
16
14
  end
data/lib/seorel/helper.rb CHANGED
@@ -3,12 +3,7 @@ module Seorel
3
3
  module Helper
4
4
 
5
5
  def render_meta_tags
6
- metas = ''
7
- metas+= render_title
8
- metas+= render_description
9
- metas+= render_open_graph
10
- metas+= render_twitter_cards
11
- metas.html_safe
6
+ [render_title, render_description, render_open_graph, render_twitter_cards].join("\n").html_safe
12
7
  end
13
8
 
14
9
  def render_title
@@ -20,23 +15,23 @@ module Seorel
20
15
  end
21
16
 
22
17
  def render_open_graph
23
- metas = ''
24
- metas+= content_tag :meta, nil, name: 'og:type', content: 'website'
25
- metas+= content_tag :meta, nil, name: 'og:title', content: seorel_params.full_title
26
- metas+= content_tag :meta, nil, name: 'og:description', content: seorel_params.description
27
- metas+= content_tag :meta, nil, name: 'og:image', content: seorel_params.image
28
- metas+= content_tag :meta, nil, name: 'og:locale', content: I18n.locale.to_s
29
- metas.html_safe
18
+ [
19
+ content_tag(:meta, nil, name: 'og:type', content: 'website'),
20
+ content_tag(:meta, nil, name: 'og:title', content: seorel_params.full_title),
21
+ content_tag(:meta, nil, name: 'og:description', content: seorel_params.description),
22
+ content_tag(:meta, nil, name: 'og:image', content: seorel_params.image),
23
+ content_tag(:meta, nil, name: 'og:locale', content: I18n.locale.to_s)
24
+ ].join("\n").html_safe
30
25
  end
31
26
 
32
27
  def render_twitter_cards
33
- metas = ''
34
- metas+= content_tag :meta, nil, name: 'twitter:card', content: 'summary'
35
- metas+= content_tag :meta, nil, name: 'twitter:url', content: url_for
36
- metas+= content_tag :meta, nil, name: 'twitter:title', content: seorel_params.full_title
37
- metas+= content_tag :meta, nil, name: 'twitter:description', content: seorel_params.description
38
- metas+= content_tag :meta, nil, name: 'twitter:image', content: seorel_params.image
39
- metas.html_safe
28
+ [
29
+ content_tag(:meta, nil, name: 'twitter:card', content: 'summary'),
30
+ content_tag(:meta, nil, name: 'twitter:url', content: url_for),
31
+ content_tag(:meta, nil, name: 'twitter:title', content: seorel_params.full_title),
32
+ content_tag(:meta, nil, name: 'twitter:description', content: seorel_params.description),
33
+ content_tag(:meta, nil, name: 'twitter:image', content: seorel_params.image)
34
+ ].join("\n").html_safe
40
35
  end
41
36
 
42
37
  end
@@ -22,7 +22,7 @@ module Seorel
22
22
  has_one :seorel, as: :seorelable, dependent: :destroy, class_name: 'Seorel::Seorel'
23
23
  accepts_nested_attributes_for :seorel, allow_destroy: false
24
24
 
25
- before_save :set_seorel_default_values
25
+ before_save :set_seorel
26
26
 
27
27
  delegate :title, :title?, :description, :description?, :image, :image?, to: :seorel, prefix: :seo, allow_nil: true
28
28
  end
@@ -7,19 +7,29 @@ module Seorel
7
7
  self.try(:seorel).present?
8
8
  end
9
9
 
10
- def set_seorel_default_values
10
+ def should_update_seo_title?
11
+ ::Seorel.config.store_seorel_if.eql?(:changed) || !self.seo_title?
12
+ end
13
+
14
+ def should_update_seo_description?
15
+ ::Seorel.config.store_seorel_if.eql?(:changed) || !self.seo_description?
16
+ end
17
+
18
+ def set_seorel
11
19
  self.build_seorel unless self.seorel?
12
20
 
13
- self.seorel.title = self.seorel_title_value if self.seorel_title_value.present?
14
- self.seorel.description = self.seorel_description_value if self.seorel_description_value.present?
21
+ self.seorel.title = self.seorel_title_value if self.should_update_seo_title?
22
+ self.seorel.description = self.seorel_description_value if self.should_update_seo_description?
15
23
  end
16
24
 
17
25
  def seorel_title_value
18
- self.class.seorel_title_field && self.send(self.class.seorel_title_field)
26
+ raw_title = self.class.seorel_title_field && self.send(self.class.seorel_title_field)
27
+ ::ActionController::Base.helpers.strip_tags(raw_title.to_s).first(255)
19
28
  end
20
29
 
21
30
  def seorel_description_value
22
- self.class.seorel_description_field && self.send(self.class.seorel_description_field)
31
+ raw_description = self.class.seorel_description_field && self.send(self.class.seorel_description_field)
32
+ ::ActionController::Base.helpers.strip_tags(raw_description.to_s).first(255)
23
33
  end
24
34
 
25
35
  def seorel_default_value?
@@ -1,3 +1,3 @@
1
1
  module Seorel
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: seorel
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-04-10 00:00:00.000000000 Z
12
+ date: 2013-10-25 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -27,54 +27,6 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: '3.2'
30
- - !ruby/object:Gem::Dependency
31
- name: carrierwave
32
- requirement: !ruby/object:Gem::Requirement
33
- none: false
34
- requirements:
35
- - - ! '>='
36
- - !ruby/object:Gem::Version
37
- version: '0'
38
- type: :runtime
39
- prerelease: false
40
- version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
- requirements:
43
- - - ! '>='
44
- - !ruby/object:Gem::Version
45
- version: '0'
46
- - !ruby/object:Gem::Dependency
47
- name: mini_magick
48
- requirement: !ruby/object:Gem::Requirement
49
- none: false
50
- requirements:
51
- - - ! '>='
52
- - !ruby/object:Gem::Version
53
- version: '0'
54
- type: :runtime
55
- prerelease: false
56
- version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
- requirements:
59
- - - ! '>='
60
- - !ruby/object:Gem::Version
61
- version: '0'
62
- - !ruby/object:Gem::Dependency
63
- name: sqlite3
64
- requirement: !ruby/object:Gem::Requirement
65
- none: false
66
- requirements:
67
- - - ! '>='
68
- - !ruby/object:Gem::Version
69
- version: '0'
70
- type: :development
71
- prerelease: false
72
- version_requirements: !ruby/object:Gem::Requirement
73
- none: false
74
- requirements:
75
- - - ! '>='
76
- - !ruby/object:Gem::Version
77
- version: '0'
78
30
  description: Easy management of SEO Metatags for your ActiveRecord models
79
31
  email:
80
32
  - info@andreadalponte.com
@@ -83,7 +35,6 @@ extensions: []
83
35
  extra_rdoc_files: []
84
36
  files:
85
37
  - app/models/seorel/seorel.rb
86
- - app/uploaders/seorel/image_uploader.rb
87
38
  - config/locales/en.seorel.yml
88
39
  - config/locales/it.seorel.yml
89
40
  - config/routes.rb
@@ -1,53 +0,0 @@
1
- # encoding: utf-8
2
- module Seorel
3
- class ImageUploader < CarrierWave::Uploader::Base
4
-
5
- # Include RMagick or MiniMagick support:
6
- # include CarrierWave::RMagick
7
- # include CarrierWave::Processing::RMagick
8
- include CarrierWave::MiniMagick
9
-
10
- # Include the Sprockets helpers for Rails 3.1+ asset pipeline compatibility:
11
- include Sprockets::Helpers::RailsHelper
12
- include Sprockets::Helpers::IsolatedHelper
13
-
14
- # Choose what kind of storage to use for this uploader:
15
- storage :file
16
- # storage :fog
17
-
18
- # Override the directory where uploaded files will be stored.
19
- # This is a sensible default for uploaders that are meant to be mounted:
20
- def store_dir
21
- File.join('system', model.class.to_s.underscore.to_s, mounted_as.to_s, model.id.to_s)
22
- end
23
-
24
- # Provide a default URL as a default if there hasn't been a file uploaded:
25
- def default_url
26
- # For Rails 3.1+ asset pipeline compatibility:
27
- asset_path('seorel/default.jpg')
28
- end
29
-
30
- process convert: 'jpeg'
31
-
32
- version :thumbnail do
33
- process resize_to_fill: [150, 150]
34
- end
35
-
36
- version :default do
37
- process resize_and_pad: [300, 300, '#ffffff']
38
- end
39
-
40
- # Add a white list of extensions which are allowed to be uploaded.
41
- # For images you might use something like this:
42
- def extension_white_list
43
- %w(jpg jpeg gif png bmp tif tiff)
44
- end
45
-
46
- # Override the filename of the uploaded files:
47
- # Avoid using model.id or version_name here, see uploader/store.rb for details.
48
- # def filename
49
- # "something.jpg" if original_filename
50
- # end
51
-
52
- end
53
- end