para-seo_tools 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (60) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +14 -0
  3. data/Gemfile +4 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +178 -0
  6. data/Rakefile +2 -0
  7. data/app/.DS_Store +0 -0
  8. data/app/components/seo_tools_skeleton_component.rb +7 -0
  9. data/app/controllers/.DS_Store +0 -0
  10. data/app/controllers/admin/para/seo_tools/skeleton_resources_controller.rb +21 -0
  11. data/app/decorators/seo_tools_skeleton_component_decorator.rb +3 -0
  12. data/app/helpers/para/seo_tools/admin/fields_helper.rb +15 -0
  13. data/app/models/para/seo_tools/page.rb +54 -0
  14. data/app/views/.DS_Store +0 -0
  15. data/app/views/admin/.DS_Store +0 -0
  16. data/app/views/admin/para/seo_tools/pages/_actions.html.haml +5 -0
  17. data/app/views/admin/para/seo_tools/pages/_filters.html.haml +25 -0
  18. data/app/views/admin/para/seo_tools/pages/_form.html.haml +13 -0
  19. data/app/views/admin/para/seo_tools/pages/_table.html.haml +20 -0
  20. data/app/views/admin/para/seo_tools/skeleton_resources/index.html.haml +4 -0
  21. data/bin/rails +12 -0
  22. data/config/locales/para-seo_tools.fr.yml +22 -0
  23. data/db/migrate/20150601085253_create_seo_tools_pages.rb +14 -0
  24. data/db/migrate/20160610094032_add_meta_tags_to_seo_tools_pages.rb +12 -0
  25. data/db/migrate/20160614081242_add_locale_and_remove_meta_tags_list_to_seo_tools_pages.rb +8 -0
  26. data/lib/generators/para/seo_tools/install/install_generator.rb +24 -0
  27. data/lib/generators/para/seo_tools/install/templates/initializer.rb +33 -0
  28. data/lib/generators/para/seo_tools/install/templates/skeleton.rb +37 -0
  29. data/lib/para/seo_tools/controller.rb +50 -0
  30. data/lib/para/seo_tools/engine.rb +27 -0
  31. data/lib/para/seo_tools/meta_tags/renderer.rb +80 -0
  32. data/lib/para/seo_tools/meta_tags/store.rb +52 -0
  33. data/lib/para/seo_tools/meta_tags/tags/base.rb +49 -0
  34. data/lib/para/seo_tools/meta_tags/tags/description.rb +54 -0
  35. data/lib/para/seo_tools/meta_tags/tags/image.rb +46 -0
  36. data/lib/para/seo_tools/meta_tags/tags/keywords.rb +20 -0
  37. data/lib/para/seo_tools/meta_tags/tags/title.rb +48 -0
  38. data/lib/para/seo_tools/meta_tags/tags/url.rb +13 -0
  39. data/lib/para/seo_tools/meta_tags/tags.rb +29 -0
  40. data/lib/para/seo_tools/meta_tags/vendors/base.rb +27 -0
  41. data/lib/para/seo_tools/meta_tags/vendors/open_graph.rb +23 -0
  42. data/lib/para/seo_tools/meta_tags/vendors/twitter.rb +23 -0
  43. data/lib/para/seo_tools/meta_tags/vendors.rb +17 -0
  44. data/lib/para/seo_tools/meta_tags.rb +12 -0
  45. data/lib/para/seo_tools/routes.rb +15 -0
  46. data/lib/para/seo_tools/sitemap.rb +13 -0
  47. data/lib/para/seo_tools/skeleton/page.rb +71 -0
  48. data/lib/para/seo_tools/skeleton/site.rb +18 -0
  49. data/lib/para/seo_tools/skeleton/worker.rb +11 -0
  50. data/lib/para/seo_tools/skeleton.rb +79 -0
  51. data/lib/para/seo_tools/version.rb +5 -0
  52. data/lib/para/seo_tools/view_helpers.rb +9 -0
  53. data/lib/para/seo_tools.rb +43 -0
  54. data/lib/tasks/migration.rake +20 -0
  55. data/lib/tasks/sitemap.rake +17 -0
  56. data/lib/tasks/skeleton.rake +9 -0
  57. data/para-seo_tools.gemspec +27 -0
  58. data/test/fixtures/seo_tools/pages.yml +11 -0
  59. data/test/models/seo_tools/page_test.rb +7 -0
  60. metadata +181 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 221bb39c998483d4271625e92a0ae8a99e60892d
4
+ data.tar.gz: 1f98d09e9135f026442dbda3f64dfeb300c1abf8
5
+ SHA512:
6
+ metadata.gz: 28d2a040ebdc391c3ae165489e2aa190560b43a84fa200bf689d6e1bcd511639762b7d59eb117828d0b5addfe6f06f355d01f07cc664353d1d336432d8ea14f0
7
+ data.tar.gz: 375e465165815264dc4b89a61afdc6097e7a6ba7941ff5173bf088f4e189b62f324cc38ae0f13712004b7d1d405b73529320fbb12570b21c7a602dcdffbeca6d
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in seo_tools-para.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2015 vala
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,178 @@
1
+ # Para::SeoTools
2
+
3
+ The SEO Tools for Para allows to configure the sitemap and meta tags for your
4
+ Para CMS powered website.
5
+
6
+ You'll be able to easily define a sitemap for your app, and get an admin panel
7
+ for filling out all the pages' meta tags.
8
+
9
+ ## Installation
10
+
11
+ Add this line to your application's Gemfile:
12
+
13
+ ```ruby
14
+ gem 'seo_tools-para'
15
+ ```
16
+
17
+ And then execute:
18
+
19
+ ```bash
20
+ bundle
21
+ ```
22
+
23
+ Or install it yourself as:
24
+
25
+ ```bash
26
+ gem install seo_tools-para
27
+ ```
28
+
29
+ Run the installation generator :
30
+
31
+ ```bash
32
+ rails generate seo_tools:install
33
+ ```
34
+
35
+ ## Usage
36
+
37
+ The idea is to define a simple Sitemap structure, and you'll be able to
38
+ edit those pages meta_tags from the admin panel, and a sitemap.xml will be
39
+ generatable with a simple Task.
40
+
41
+ In the following section, you'll find how to :
42
+
43
+ 1. Define the sitemap
44
+ 2. Display the meta tags admin panel
45
+ 3. Generate a sitemap.xml
46
+ 4. Retrieving meta tags in your app
47
+
48
+
49
+ ### 1. Define the sitemap
50
+
51
+ When you run the `seo_tools:install` generator, a file is created at
52
+ `config/skeleton.rb` for you to create the sitemap.
53
+
54
+ This file allows you to define which pages you want to make available for
55
+ search engines indexation and optimization, through a simple DSL.
56
+
57
+ The pages are defined with the `page` method, and accepts some options.
58
+
59
+ The following will define the page `posts` and call `posts_path` to retrieve
60
+ its URL
61
+
62
+ ```ruby
63
+ page :posts
64
+ ```
65
+
66
+ If you want to define the page path yourself, just add the `:path` option
67
+ to the `page` call
68
+
69
+ ```ruby
70
+ page :home, path: root_path
71
+ ```
72
+
73
+ When the page is linked to a resource : often, a #show page, you'll need to
74
+ pass the `:resource` option
75
+
76
+ ```ruby
77
+ Posts.find_each do |post|
78
+ page :post, resource: post
79
+ end
80
+ ```
81
+
82
+ Also, you can pass options for the sitemap generation tool.
83
+ The options are `:priority`, `:change_frequency` which are left blank
84
+ by default.
85
+
86
+ ```ruby
87
+ page :posts, priority: 1, change_frequency: 'weekly'
88
+ ```
89
+
90
+ ### 2. Display the meta tags admin panel
91
+
92
+ For the admin panel to display, all you'll need to do is create the component
93
+ in your Para's `components.rb`.
94
+
95
+ > Note : For more informations on the `components.rb` file, please see the
96
+ > [Para documentation](https://github.com/para-cms/para/wiki/Components-configuration)
97
+
98
+ Add the component to your `config/components.rb` file :
99
+
100
+ ```ruby
101
+ section :your_section do
102
+ component :sitemap, :seo_tools_skeleton
103
+ end
104
+ ```
105
+
106
+ The go to the admin panel, and click the **Sitemap** menu link.
107
+
108
+ ### 3. Generate a sitemap.xml
109
+
110
+ Sitemap generation is accomplished through the use of the
111
+ [rails-sitemap](https://github.com/viseztrance/rails-sitemap) gem,
112
+ with a custom task to integrate easily with `seo_tools-para`.
113
+
114
+ You'll first need to configure your application's host name.
115
+ This can be defined in the generated initializer or in an environment variable.
116
+
117
+ In the `config/initializers/seo_tools.rb` initializer :
118
+
119
+ ```ruby
120
+ config.host = "www.mydomain.com"
121
+ ```
122
+
123
+ Or with the `APP_DOMAIN` environment variable.
124
+
125
+ ```bash
126
+ APP_DOMAIN="www.mydomain.com"
127
+ ```
128
+
129
+ Generating the sitemap can be done with the dedicated rake task :
130
+
131
+ ```bash
132
+ rake seo_tools:sitemap:generate
133
+ ```
134
+
135
+ You can pass a `LOCATION` environment variable to define where to store it.
136
+ By default, it will be stored at : `public/sitemap.xml`
137
+
138
+ ```bash
139
+ rake seo_tools:sitemap:generate LOCATION=/home/user/apps/my-app/shared
140
+ ```
141
+
142
+ ### 4. Retrieving meta tags in your app
143
+
144
+ Meta tags edition and rendering is done through the
145
+ [meta_tags](https://github.com/glyph-fr/meta_tags) gem.
146
+
147
+ For more informations on customizing its behavior, please see the
148
+ [meta_tags documentation](https://github.com/glyph-fr/meta_tags).
149
+
150
+ The meta tags are automatically retrieved from the current page path by default.
151
+
152
+ `seo_tools-para` includes a `before_action` callback that fetches the existing
153
+ meta tags for the current path, and sets them in your page.
154
+
155
+ All you need to do is to include the following in your layout file, at the top
156
+ of your `<head>` tag, since `meta_tags` automatically appends the
157
+ `<meta encoding="utf-8">` tag.
158
+
159
+ ```erb
160
+ <html>
161
+ <head>
162
+ <%= meta_tags %>
163
+ ...
164
+ </head>
165
+ <body>
166
+ ...
167
+ </body>
168
+ </html>
169
+ ```
170
+
171
+
172
+ ## Contributing
173
+
174
+ 1. Fork it ( https://github.com/[my-github-username]/seo_tools-para/fork )
175
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
176
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
177
+ 4. Push to the branch (`git push origin my-new-feature`)
178
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/app/.DS_Store ADDED
Binary file
@@ -0,0 +1,7 @@
1
+ class SeoToolsSkeletonComponent < Para::Component::Crud
2
+ register :seo_tools_skeleton, self
3
+
4
+ def model_type
5
+ '::Para::SeoTools::Page'
6
+ end
7
+ end
Binary file
@@ -0,0 +1,21 @@
1
+ module Admin
2
+ module Para
3
+ module SeoTools
4
+ class SkeletonResourcesController < ::Para::Admin::CrudResourcesController
5
+ def index
6
+ super
7
+ @available_locales = ::Para::SeoTools::Page.group(:locale).pluck(:locale)
8
+ end
9
+
10
+ def refresh
11
+ ::Para::SeoTools::Skeleton.with_logging do
12
+ ::Para::SeoTools::Skeleton.load
13
+ ::Para::SeoTools::Skeleton::Worker.perform
14
+ end
15
+
16
+ redirect_to after_form_submit_path
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,3 @@
1
+ module SeoToolsSkeletonComponentDecorator
2
+ include Para::Component::CrudDecorator
3
+ end
@@ -0,0 +1,15 @@
1
+ module Para
2
+ module SeoTools
3
+ module Admin
4
+ module FieldsHelper
5
+ def meta_tag_input(form, name, options = {})
6
+ options[:hint] ||= if (default = form.object.default(name))
7
+ t('para.seo_tools.pages.default_meta_tag_value', value: default).html_safe
8
+ end
9
+
10
+ form.input name, options
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,54 @@
1
+ module Para
2
+ module SeoTools
3
+ class Page < ActiveRecord::Base
4
+ META_TAGS = :title, :description, :keywords, :image, :canonical
5
+
6
+ has_attached_file :image, styles: { thumb: '200x200#' }
7
+ validates_attachment :image, content_type: { content_type: /\Aimage\/.*\Z/ }
8
+
9
+ def meta_tag(name)
10
+ process(name, send(name)).presence || default(name)
11
+ end
12
+
13
+ def defaults
14
+ if (hash = read_attribute(:defaults))
15
+ hash
16
+ else
17
+ self.defaults = {}
18
+ end
19
+ end
20
+
21
+ def default(name)
22
+ process(name, defaults[name.to_s]) if defaults[name.to_s]
23
+ end
24
+
25
+ ransacker :title do |parent|
26
+ default_title = Arel::Nodes::InfixOperation.new('->>', parent.table[:defaults], Arel::Nodes.build_quoted('title'))
27
+ expr = Arel::Nodes::NamedFunction.new('COALESCE', [parent.table[:title], default_title])
28
+
29
+ # Conversion to Arel::Nodes::SqlLiteral is required for sorting to work,
30
+ # since the Arel::Nodes::NamedFunction doesn't include Arel ordering
31
+ # methods, and Ransack uses them
32
+ #
33
+ Arel::Nodes::SqlLiteral.new(expr.to_sql)
34
+ end
35
+
36
+ ransacker :description do |parent|
37
+ default_description = Arel::Nodes::InfixOperation.new('->>', parent.table[:defaults], Arel::Nodes.build_quoted('description'))
38
+ expr = Arel::Nodes::NamedFunction.new('COALESCE',[parent.table[:description], default_description])
39
+
40
+ Arel::Nodes::SqlLiteral.new(expr.to_sql)
41
+ end
42
+
43
+ private
44
+
45
+ def process(name, value)
46
+ if (processor = Para::SeoTools::MetaTags::Tags[name])
47
+ processor.process(value)
48
+ else
49
+ value
50
+ end
51
+ end
52
+ end
53
+ end
54
+ end
Binary file
Binary file
@@ -0,0 +1,5 @@
1
+ %ul.panel-controls
2
+ %li
3
+ = link_to @component.relation_path(action: :refresh, return_to: request.fullpath), class: 'btn btn-default' do
4
+ = fa_icon 'refresh'
5
+ = t('para.seo_tools.pages.refresh_skeleton')
@@ -0,0 +1,25 @@
1
+ = search_form_for @q, builder: SimpleForm::FormBuilder, url: @component.path, html: { data: { :'filters-form' => true } } do |form|
2
+ - if @available_locales.length > 1
3
+ .row
4
+ .col-md-3
5
+ = form.input_field :locale_eq, as: :selectize, collection: @available_locales, class: 'form-control', placeholder: t('para.seo_tools.pages.choose_locale')
6
+
7
+ .col-md-7
8
+ .input-group
9
+ %span.input-group-addon
10
+ %i.fa.fa-search
11
+
12
+ = form.input_field :identifier_or_path_or_title_or_description_or_keywords_or_canonical_cont, as: :string, placeholder: t('para.shared.search'), class: 'form-control'
13
+
14
+ .col-md-2
15
+ = form.submit t('para.shared.search'), class: 'btn btn-default btn-block'
16
+
17
+ - else
18
+ .input-group
19
+ %span.input-group-addon
20
+ %i.fa.fa-search
21
+
22
+ = form.input_field :identifier_or_path_or_title_or_description_or_keywords_or_canonical_cont, as: :string, placeholder: t('para.shared.search'), class: 'form-control'
23
+
24
+ %span.input-group-btn
25
+ = form.submit t('para.shared.search'), class: 'btn btn-default'
@@ -0,0 +1,13 @@
1
+ = para_form_for(resource) do |form|
2
+ = form.fieldset do
3
+ = form.input :path, disabled: true
4
+
5
+ = meta_tag_input form, :title
6
+ = meta_tag_input form, :description
7
+ = meta_tag_input form, :keywords
8
+
9
+ = form.fieldset title: t('para.seo_tools.pages.additional_meta_tags') do
10
+ = meta_tag_input form, :image, as: :image
11
+ = meta_tag_input form, :canonical
12
+
13
+ = form.actions
@@ -0,0 +1,20 @@
1
+ = resources_table(model: model, component: component, actions: false) do |table|
2
+ = table.header do
3
+ = table.header_for(:path)
4
+ = table.header_for(:title)
5
+ = table.header_for(:description)
6
+ = table.header_for(:locale) if @available_locales.length > 1
7
+ %th
8
+
9
+ = table.rows(resources) do |resource|
10
+ = table.data_for(resource, :path)
11
+ = table.data_for(resource.meta_tag(:title))
12
+ = table.data_for(resource.meta_tag(:description))
13
+ = table.data_for(resource, :locale) if @available_locales.length > 1
14
+
15
+ %td
16
+ .pull-right.btn-group
17
+ = table.edit_button(resource)
18
+
19
+ = link_to resource.path, target: '_blank', class: 'btn btn-default hint--left', data: { hint: t('para.seo_tools.pages.see_in_app') } do
20
+ = fa_icon 'eye'
@@ -0,0 +1,4 @@
1
+ .page-title
2
+ %h1= @component.name
3
+
4
+ = listing_for(@resources, addable: false)
data/bin/rails ADDED
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 4 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+ ENGINE_PATH = File.expand_path('../../lib/para/seo_tools/engine', __FILE__)
6
+
7
+ # Set up gems listed in the Gemfile.
8
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
9
+ require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
10
+
11
+ require 'rails/all'
12
+ require 'rails/engine/commands'
@@ -0,0 +1,22 @@
1
+ fr:
2
+ para:
3
+ seo_tools:
4
+ pages:
5
+ see_in_app: "Voir la page"
6
+ default_meta_tag_value: "Valeur par défaut : <b>%{value}</b>"
7
+ additional_meta_tags: "Meta-données avancées"
8
+ refresh_skeleton: "Mettre à jour"
9
+ choose_locale: "Choisissez une langue"
10
+
11
+ activerecord:
12
+ attributes:
13
+ para/seo_tools/page:
14
+ path: "URL de la page"
15
+ identifier: "Identifiant de la page"
16
+ title: "Titre"
17
+ description: "Description"
18
+ keywords: "Mots-clés de la page"
19
+ image: "Image pour le partage sur les réseaux sociaux"
20
+ canonical: "URL canonique"
21
+ locale: "Langue"
22
+
@@ -0,0 +1,14 @@
1
+ class CreateSeoToolsPages < ActiveRecord::Migration
2
+ def change
3
+ create_table :seo_tools_pages do |t|
4
+ t.string :identifier
5
+ t.string :path
6
+ t.references :meta_tags_list, index: true, foreign_key: true
7
+
8
+ t.timestamps null: false
9
+ end
10
+
11
+ add_index :seo_tools_pages, :identifier
12
+ add_index :seo_tools_pages, :path
13
+ end
14
+ end
@@ -0,0 +1,12 @@
1
+ class AddMetaTagsToSeoToolsPages < ActiveRecord::Migration
2
+ def change
3
+ change_table :seo_tools_pages do |t|
4
+ t.string :title
5
+ t.text :description
6
+ t.text :keywords
7
+ t.attachment :image
8
+ t.text :canonical
9
+ t.jsonb :defaults
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,8 @@
1
+ class AddLocaleAndRemoveMetaTagsListToSeoToolsPages < ActiveRecord::Migration
2
+ def change
3
+ change_table :seo_tools_pages do |t|
4
+ t.remove_references :meta_tags_list, index: true
5
+ t.string :locale
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,24 @@
1
+ module Para
2
+ module SeoTools
3
+ class InstallGenerator < Rails::Generators::Base
4
+ # Copied files come from templates folder
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ # Generator desc
8
+ desc 'Seo Tools install generator'
9
+
10
+ def copy_initializer_file
11
+ copy_file 'initializer.rb', 'config/initializers/seo_tools.rb'
12
+ end
13
+
14
+ def copy_and_run_migrations
15
+ rake 'para_seo_tools_engine:install:migrations'
16
+ rake 'db:migrate'
17
+ end
18
+
19
+ def create_skeleton_file
20
+ copy_file 'skeleton.rb', 'config/skeleton.rb'
21
+ end
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,33 @@
1
+ Para::SeoTools.configure do |config|
2
+ # Configure the hostname for the sitemap
3
+ #
4
+ # Defaults to the ENV['APP_DOMAIN'] variable
5
+ #
6
+ # config.host = ENV['APP_DOMAIN']
7
+
8
+ # Default title methods to be checked for title
9
+ #
10
+ # config.title_methods = %w(title name)
11
+
12
+ # Default methods to be checked for description
13
+ #
14
+ # config.description_methods = %w(description desc content)
15
+
16
+ # Default image methods to be checked for image
17
+ #
18
+ # config.image_methods = %w(image picture avatar)
19
+
20
+ # Configure the default meta tags that will be used when no source could
21
+ # fill the defined meta.
22
+ #
23
+ # One good thing is to configure the title here to avoid empty <title> tags.
24
+ # But you can configure any supported meta tag here.
25
+ #
26
+ # Note that you'll need to pass a proc or lambda, and that it'll be executed
27
+ # in the context of the controller.
28
+ # This allows for example to set I18n aware defaults.
29
+ #
30
+ # config.defaults = lambda do
31
+ # { title: 'My website' }
32
+ # end
33
+ end
@@ -0,0 +1,37 @@
1
+ # Use `lazy: true` to avoid generating the pages skeleton on server run
2
+ #
3
+ # You'll then have to run `rake seo_tools:skeleton:build` to refresh it or use
4
+ # the `Para::SeoTools::Skeleton::Worker.perform` method in some worker to
5
+ # refresh it periodically
6
+ #
7
+ # Note that you also have to always refresh the sitemap manually with the
8
+ # following task : `rake seo_tools:sitemap:generate`
9
+ #
10
+ Para::SeoTools::Skeleton.draw(lazy: false) do
11
+ # Define your website SEO targetted structure here.
12
+ # Pages are defined with the `page` method, and allows for some options.
13
+ #
14
+ # The following will define the page `posts` and call `posts_path` to retrieve
15
+ # its URL
16
+ #
17
+ # page :posts
18
+ #
19
+ # If you want to define the page path yourself, just add the `:path` option
20
+ # to the `page` call
21
+ #
22
+ # page :home, path: root_path
23
+ #
24
+ # When the page is linked to a resource : often, a #show page, you'll need to
25
+ # pass the `:resource` option
26
+ #
27
+ # Posts.find_each do |post|
28
+ # page :post, resource: post
29
+ # end
30
+ #
31
+ # Also, you can pass options for the sitemap generation tool.
32
+ # The options are `:priority`, `:change_frequency` which are left blank
33
+ # by default.
34
+ #
35
+ # page :posts, priority: 1, change_frequency: 'weekly'
36
+ #
37
+ end
@@ -0,0 +1,50 @@
1
+ module Para
2
+ module SeoTools
3
+ module Controller
4
+ extend ActiveSupport::Concern
5
+
6
+ included do
7
+ before_action :store_request_for_meta_tags_processing
8
+ helper_method :meta_tags_store
9
+ before_action :fetch_meta_tags_page
10
+ end
11
+
12
+ def meta_tags_store
13
+ @meta_tags_store ||= MetaTags::Store.new(self)
14
+ end
15
+
16
+ protected
17
+
18
+ def meta_tags_from(resource)
19
+ @instance = resource
20
+ end
21
+
22
+ def set_meta_tags_from_page(page)
23
+ if page.kind_of?(Para::SeoTools::Page)
24
+ Para::SeoTools::Page::META_TAGS.each do |tag_name|
25
+ if (value = page.meta_tag(tag_name)).present?
26
+ set_meta_tag(tag_name, value)
27
+ end
28
+ end
29
+ else
30
+ page = Para::SeoTools::Page.where(identifier: page.to_s).first
31
+ set_meta_tags_from_page(page) if page
32
+ end
33
+ end
34
+
35
+ def set_meta_tag(tag_name, value)
36
+ meta_tags_store.send(:"#{ tag_name }=", value)
37
+ end
38
+
39
+ def fetch_meta_tags_page
40
+ if (page = Para::SeoTools::Page.find_by_path(request.path))
41
+ set_meta_tags_from_page(page)
42
+ end
43
+ end
44
+
45
+ def store_request_for_meta_tags_processing
46
+ RequestStore.store[:'para.seo_tools.request'] = request
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,27 @@
1
+ module Para
2
+ module SeoTools
3
+ class Engine < Rails::Engine
4
+ config.after_initialize do
5
+ Para::SeoTools::Skeleton.load
6
+ end
7
+
8
+ initializer 'para.seo_tools.include_controller_mixin' do
9
+ ActiveSupport.on_load(:action_controller) do
10
+ include Para::SeoTools::Controller
11
+ end
12
+ end
13
+
14
+ initializer "para.seo_tools.include_view_helpers" do
15
+ ActiveSupport.on_load(:action_view) do
16
+ include Para::SeoTools::ViewHelpers
17
+ end
18
+ end
19
+
20
+ rake_tasks do
21
+ Dir[File.expand_path('../../tasks/**/*.rake', __FILE__)].each do |path|
22
+ load(path)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end