para-seo_tools 0.2.1 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 221bb39c998483d4271625e92a0ae8a99e60892d
4
- data.tar.gz: 1f98d09e9135f026442dbda3f64dfeb300c1abf8
3
+ metadata.gz: a34f864ccd5b3365f87eff521544ce23fe555c6a
4
+ data.tar.gz: 98b4747257ce0acd81643e9c0b101e9706fbadb5
5
5
  SHA512:
6
- metadata.gz: 28d2a040ebdc391c3ae165489e2aa190560b43a84fa200bf689d6e1bcd511639762b7d59eb117828d0b5addfe6f06f355d01f07cc664353d1d336432d8ea14f0
7
- data.tar.gz: 375e465165815264dc4b89a61afdc6097e7a6ba7941ff5173bf088f4e189b62f324cc38ae0f13712004b7d1d405b73529320fbb12570b21c7a602dcdffbeca6d
6
+ metadata.gz: bf073b75a0b537fef122a1cec5614505b1e6e0ca0288f417a917bf68ffe015fd663de442fcde4fdda9d7de28791524e8be8acea01a5f9e0b098f318a5a9a9883
7
+ data.tar.gz: 6660839f153d03a48b1957aef6dc1118e8456957d3fc00e8fb729ad015ac921074eaa7c0633fdb6bd9bdd78505e39f5994dec455033bfe38e554150aad3683f3
data/.gitignore CHANGED
@@ -12,3 +12,4 @@
12
12
  *.o
13
13
  *.a
14
14
  mkmf.log
15
+ *.gem
@@ -4,4 +4,8 @@ class SeoToolsSkeletonComponent < Para::Component::Crud
4
4
  def model_type
5
5
  '::Para::SeoTools::Page'
6
6
  end
7
+
8
+ def controller
9
+ :skeleton_resources
10
+ end
7
11
  end
@@ -1,6 +1,6 @@
1
- module Admin
2
- module Para
3
- module SeoTools
1
+ module Para
2
+ module SeoTools
3
+ module Admin
4
4
  class SkeletonResourcesController < ::Para::Admin::CrudResourcesController
5
5
  def index
6
6
  super
@@ -7,7 +7,11 @@ module Para
7
7
  validates_attachment :image, content_type: { content_type: /\Aimage\/.*\Z/ }
8
8
 
9
9
  def meta_tag(name)
10
- process(name, send(name)).presence || default(name)
10
+ if (value = send(name).presence) && (meta = process(name, value)).present?
11
+ return meta
12
+ end
13
+
14
+ default(name)
11
15
  end
12
16
 
13
17
  def defaults
@@ -16,12 +16,6 @@ module Para
16
16
  include Para::SeoTools::ViewHelpers
17
17
  end
18
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
19
  end
26
20
  end
27
21
  end
@@ -13,8 +13,11 @@ module Para
13
13
  if url.start_with?('http://')
14
14
  url
15
15
  else
16
- request = RequestStore.store[:'para.seo_tools.request']
17
- URI.join(request.url, url).to_s
16
+ if (request = RequestStore.store[:'para.seo_tools.request'])
17
+ URI.join(request.url, url).to_s
18
+ else
19
+ url
20
+ end
18
21
  end
19
22
  end
20
23
 
@@ -3,7 +3,7 @@ module Para
3
3
  class Routes < Para::Plugins::Routes
4
4
  def draw
5
5
  plugin :seo_tools do
6
- crud_component :skeleton, scope: ':model' do
6
+ crud_component :seo_tools_skeleton, scope: ':model', controller: :skeleton_resources do
7
7
  collection do
8
8
  get :refresh
9
9
  end
@@ -2,9 +2,9 @@ module Para
2
2
  module SeoTools
3
3
  class Sitemap
4
4
  def self.build
5
- ::Sitemap::Generator.instance.load :host => Para::SeoTools.host do
6
- Para::SeoTools::Skeleton.site.pages.each do |page|
7
- literal page.path, page.sitemap_options
5
+ ::Sitemap::Generator.instance.load host: Para::SeoTools.host do
6
+ Para::SeoTools::Page.find_each do |page|
7
+ literal page.path
8
8
  end
9
9
  end
10
10
  end
@@ -3,15 +3,53 @@ module Para
3
3
  module Skeleton
4
4
  class Site
5
5
  include Rails.application.routes.url_helpers
6
+ attr_reader :enable_logging
7
+
8
+ def initialize(options = {})
9
+ @enable_logging = options[:enable_logging]
10
+ end
6
11
 
7
12
  def page(name, options = {} , &block)
8
- page = Skeleton::Page.new(name, options)
9
- pages << page
13
+ Skeleton::Page.new(name, options).tap do |page|
14
+ pages << page
15
+ save if pages.length == max_pages_before_save
16
+ end
10
17
  end
11
18
 
12
19
  def pages
13
20
  @pages ||= []
14
21
  end
22
+
23
+ def save
24
+ log " * Saving #{ pages.length } generated pages ..."
25
+
26
+ ActiveRecord::Base.transaction do
27
+ pages.each do |page|
28
+ page.model.save!
29
+ saved_pages_ids << page.model.id
30
+ end
31
+ end
32
+
33
+ pages.clear
34
+ end
35
+
36
+ def saved_pages_ids
37
+ @saved_pages_ids ||= []
38
+ end
39
+
40
+ # Log messages when you're not in rails
41
+ #
42
+ def log(message)
43
+ Rails.logger.info(message) if enable_logging || !$0.end_with?('rails')
44
+ end
45
+
46
+ def max_pages_before_save
47
+ @max_pages_before_save ||= if (param = ENV['SEO_TOOLS_MAX_PAGES_BEFORE_SAVE']).present?
48
+ para.to_i
49
+ else
50
+ 500
51
+ end
52
+ end
15
53
  end
16
54
  end
17
55
  end
@@ -36,19 +36,13 @@ module Para
36
36
 
37
37
  log " * Building app skeleton pages ..."
38
38
 
39
- self.site = Skeleton::Site.new
39
+ self.site = Skeleton::Site.new(enable_logging: enable_logging)
40
40
  # Evaluate the configuration block
41
41
  site.instance_exec(&config)
42
42
 
43
- # Save all the pages to database
43
+ # Save remaining pages and remove old pages
44
44
  ActiveRecord::Base.transaction do
45
- log " * Saving generated pages ..."
46
-
47
- site.pages.each do |page|
48
- page.model.save!
49
- end
50
-
51
- log " * Destroying old pages ..."
45
+ site.save
52
46
 
53
47
  # Delete pages not in skeleton
54
48
  destroy_deleted_pages!
@@ -60,13 +54,9 @@ module Para
60
54
  end
61
55
 
62
56
  def self.destroy_deleted_pages!
63
- identifiers = site.pages.map(&:identifier)
64
- pages = Para::SeoTools::Page.where.not(identifier: identifiers)
65
-
66
- if (count = pages.count) > 0
67
- log "Destroying #{ count } removed pages from Skeleton"
68
- pages.destroy_all
69
- end
57
+ pages = Para::SeoTools::Page.where.not(id: site.saved_pages_ids)
58
+ log " * Destroying old pages ..."
59
+ pages.delete_all
70
60
  end
71
61
 
72
62
  # Log messages when you're not in rails
@@ -1,5 +1,5 @@
1
1
  module Para
2
2
  module SeoTools
3
- VERSION = "0.2.1"
3
+ VERSION = "0.3.0"
4
4
  end
5
5
  end
@@ -17,7 +17,7 @@ module Para
17
17
  autoload :MetaTaggableMacro
18
18
  autoload :ViewHelpers
19
19
 
20
- mattr_accessor :host
20
+ mattr_writer :host
21
21
  @@host = ENV['APP_DOMAIN']
22
22
 
23
23
  mattr_accessor :title_methods
@@ -39,5 +39,9 @@ module Para
39
39
  def self.table_name_prefix
40
40
  'seo_tools_'
41
41
  end
42
+
43
+ def self.host
44
+ @@host.presence && @@host.match(/[^:]+/)[0]
45
+ end
42
46
  end
43
47
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: para-seo_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Valentin Ballestrino
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-14 00:00:00.000000000 Z
11
+ date: 2016-09-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -102,7 +102,7 @@ files:
102
102
  - app/.DS_Store
103
103
  - app/components/seo_tools_skeleton_component.rb
104
104
  - app/controllers/.DS_Store
105
- - app/controllers/admin/para/seo_tools/skeleton_resources_controller.rb
105
+ - app/controllers/para/seo_tools/admin/skeleton_resources_controller.rb
106
106
  - app/decorators/seo_tools_skeleton_component_decorator.rb
107
107
  - app/helpers/para/seo_tools/admin/fields_helper.rb
108
108
  - app/models/para/seo_tools/page.rb