landable 1.11.1 → 1.12.1

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: 7eeff5bea21d975e1a609fae486601fd56f01d14
4
- data.tar.gz: 5166ca9ae9d0ce55bc358e277f9ecffea37fbd7e
3
+ metadata.gz: 5e388115c83b9777fbb1f77c0e3d0cc81b25449f
4
+ data.tar.gz: d0afa913ce591d46f56b782d73e55e422051a1cc
5
5
  SHA512:
6
- metadata.gz: 7c1cf3cead1831d185ad8054651c6f6caf69e933aa1662a775011857a66e89ec4f337a408ebbe597cbcab12b1ab7fec6df48e457303ad6e337ac5c2990122b90
7
- data.tar.gz: fad90831911bae1b77ed361ee0ad66bc1e643316798c92fa9fab99764cce0bb5975b0814933dd62283ed643d6732b7390874221ef5daf3252368f4e50d713d3c
6
+ metadata.gz: 5e861cf8d4c43e405298c592ec75b147c7b7075b92863e74b63d24d1889079df741cd1c0a43628135d1c151771b70996da323f053b54fe83fed2de089980c6c6
7
+ data.tar.gz: ed5f727a8d7b71ac73d15b1d39ba24ea0896d65b268a7d32ee33c66e8247084c31f3dd82c7ada7645e5b0c5fe4cb5a594e0bd94e2fc9f952ebb5e98ccdddecf0
data/CHANGELOG.md CHANGED
@@ -2,7 +2,13 @@
2
2
 
3
3
  See README.md before updating this file.
4
4
 
5
- ## Unreleased [#](https://github.com/enova/landable/compare/v1.11.1...master)
5
+ ## Unreleased [#](https://github.com/enova/landable/compare/v1.12.1...master)
6
+
7
+ ## 1.12.1 [#](https://github.com/enova/landable/compare/v1.11.1...v1.12.1)
8
+ * Feature: Preview For Templates [#44]
9
+ * Refactor: Clean Up MetaTags Decorator [#41]
10
+ * Feature: Show which Pages a Template Lives On [#43]
11
+ * BugFix: Deleted templates not rendered in page [#42]
6
12
 
7
13
  ## 1.11.1 [#](https://github.com/enova/landable/compare/v1.11.0...v1.11.1)
8
14
  * Adding PageName [#39]
@@ -58,13 +58,7 @@ module Landable
58
58
 
59
59
  # run the validators and render
60
60
  if page.valid?
61
- if layout = page.theme.try(:file) || false
62
- content = with_format(:html) do
63
- render_to_string text: RenderService.call(page), layout: layout
64
- end
65
- else
66
- content = RenderService.call(page, preview: true)
67
- end
61
+ content = generate_preview_for(page)
68
62
  end
69
63
 
70
64
  respond_to do |format|
@@ -98,17 +92,6 @@ module Landable
98
92
  hash[:search] || {}
99
93
  end
100
94
  end
101
-
102
- def with_format(format, &block)
103
- old_formats = formats
104
-
105
- begin
106
- self.formats = [format]
107
- return block.call
108
- ensure
109
- self.formats = old_formats
110
- end
111
- end
112
95
 
113
96
  def page_params
114
97
  params[:page][:audit_flags] ||= []
@@ -4,7 +4,7 @@ module Landable
4
4
  module Api
5
5
  class TemplatesController < ApiController
6
6
  # filters
7
- before_filter :load_template, except: [:create, :index]
7
+ before_filter :load_template, except: [:create, :index, :preview]
8
8
 
9
9
  # RESTful methods
10
10
  def create
@@ -48,6 +48,26 @@ module Landable
48
48
  respond_with @template
49
49
  end
50
50
 
51
+ # custom methods
52
+ def preview
53
+ template = Template.new(template_params)
54
+ theme = Theme.most_used_on_pages
55
+
56
+ page = Page.example(theme: theme, body: template.body)
57
+
58
+ content = generate_preview_for(page)
59
+
60
+ respond_to do |format|
61
+ format.html do
62
+ render text: content, layout: false, content_type: 'text/html'
63
+ end
64
+
65
+ format.json do
66
+ render json: { template: { preview: content } }
67
+ end
68
+ end
69
+ end
70
+
51
71
  private
52
72
  def template_params
53
73
  params.require(:template).permit(:id, :name, :body, :description, :thumbnail_url,
@@ -64,6 +64,27 @@ module Landable
64
64
  head :unauthorized if current_author.nil?
65
65
  end
66
66
 
67
+ def with_format(format, &block)
68
+ old_formats = formats
69
+
70
+ begin
71
+ self.formats = [format]
72
+ return block.call
73
+ ensure
74
+ self.formats = old_formats
75
+ end
76
+ end
77
+
78
+ def generate_preview_for(page)
79
+ if layout = page.theme.try(:file) || false
80
+ with_format(:html) do
81
+ render_to_string text: RenderService.call(page), layout: layout
82
+ end
83
+ else
84
+ RenderService.call(page, preview: true)
85
+ end
86
+ end
87
+
67
88
  def current_author
68
89
  return @current_author if @current_author
69
90
  authenticate_with_http_basic do |username, token|
@@ -28,11 +28,9 @@ module Landable
28
28
  end
29
29
 
30
30
  def meta_tags
31
- return unless tags = page.meta_tags
32
- Rails.logger.info "Meta tags string: #{tags}" if tags.is_a? String
33
- return if tags.empty? or !tags.is_a? Hash
31
+ return nil unless page.meta_tags?
34
32
 
35
- tags.map { |name, value|
33
+ page.meta_tags.map { |name, value|
36
34
  tag('meta', name: name, content: value) if value.present?
37
35
  }.compact.join("\n").html_safe
38
36
  end
@@ -30,7 +30,7 @@ module Landable
30
30
  validates :redirect_url, url: true, allow_blank: true
31
31
  validate :hero_asset_existence
32
32
 
33
- belongs_to :theme, class_name: 'Landable::Theme', inverse_of: :pages
33
+ belongs_to :theme, class_name: 'Landable::Theme', inverse_of: :pages, counter_cache: true
34
34
  belongs_to :published_revision, class_name: 'Landable::PageRevision'
35
35
  belongs_to :category, class_name: 'Landable::Category'
36
36
  belongs_to :updated_by_author, class_name: 'Landable::Author'
@@ -19,6 +19,8 @@ module Landable
19
19
 
20
20
  has_and_belongs_to_many :pages, join_table: Page.templates_join_table_name
21
21
 
22
+ delegate :count, to: :pages, prefix: true # Returns how many Pages a Template lives in!
23
+
22
24
  before_save -> template {
23
25
  template.is_publishable = true unless template.published_revision_id_changed?
24
26
  }
@@ -16,6 +16,10 @@ module Landable
16
16
  return unless table_exists?
17
17
  Layout.all.map(&:to_theme)
18
18
  end
19
+
20
+ def most_used_on_pages
21
+ order('pages_count DESC').first
22
+ end
19
23
  end
20
24
  end
21
25
  end
@@ -10,5 +10,7 @@ module Landable
10
10
 
11
11
  embed :ids
12
12
  has_one :published_revision
13
+
14
+ has_many :pages
13
15
  end
14
16
  end
data/config/routes.rb CHANGED
@@ -27,6 +27,7 @@ Landable::Engine.routes.draw do
27
27
  end
28
28
 
29
29
  resources :templates, only: [:index, :show, :create, :update, :destroy, :reactivate] do
30
+ post 'preview', on: :collection
30
31
  post 'publish', on: :member
31
32
  put 'reactivate', on: :member
32
33
  resources :audits, only: [:create]
@@ -0,0 +1,13 @@
1
+ class AddCounterForThemesPages < ActiveRecord::Migration
2
+ def up
3
+ add_column "#{Landable.configuration.database_schema_prefix}landable.themes", :pages_count, :integer, default: 0, null: false
4
+
5
+ Landable::Theme.all.each do |t|
6
+ Landable::Theme.reset_counters(t.id, :pages)
7
+ end
8
+ end
9
+
10
+ def down
11
+ remove_column "#{Landable.configuration.database_schema_prefix}landable.themes", :pages_count
12
+ end
13
+ end
@@ -42,6 +42,11 @@
42
42
  "type": "boolean"
43
43
  },
44
44
 
45
+ "page_ids": {
46
+ "type": "array",
47
+ "items": { "$ref": "uuid.json" }
48
+ },
49
+
45
50
  "thumbnail_url": {
46
51
  "type": ["string", "null"]
47
52
  },
@@ -73,6 +73,9 @@ module Landable
73
73
  def render(context)
74
74
  template = Landable::Template.find_by_slug @template_slug
75
75
 
76
+ # Handle Templates that are deleted (don't render anything)
77
+ return if template && template.deleted_at?
78
+
76
79
  # Handle Templates that are Partials
77
80
  if template && template.partial?
78
81
  responder = context.registers[:responder]
@@ -1,7 +1,7 @@
1
1
  module Landable
2
2
  module VERSION
3
3
  MAJOR = 1
4
- MINOR = 11
4
+ MINOR = 12
5
5
  PATCH = 1
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
@@ -0,0 +1,43 @@
1
+ require 'spec_helper'
2
+
3
+ module Landable::Api
4
+ describe TemplatesController, json: true do
5
+ routes { Landable::Engine.routes }
6
+
7
+ describe '#preview', json: false do
8
+ include_examples 'Authenticated API controller', :make_request
9
+ render_views
10
+
11
+ let(:theme) { create :theme, body: '<html><head>{% head_content %}</head><body>Theme content; page content: {{body}}</body></html>' }
12
+
13
+ before do
14
+ request.env['HTTP_ACCEPT'] = 'text/html'
15
+ end
16
+
17
+ def make_request(attributes = attributes_for(:template, theme_id: theme.id))
18
+ post :preview, template: attributes
19
+ end
20
+
21
+ it 'renders JSON' do
22
+ request.env['HTTP_ACCEPT'] = 'application/json'
23
+ make_request
24
+ response.status.should == 200
25
+ last_json['template']['preview'].should be_present
26
+ end
27
+
28
+ it 'renders the layout without content if the body is not present' do
29
+ request.env['HTTP_ACCEPT'] = 'application/json'
30
+ make_request attributes_for(:page, body: nil)
31
+ response.status.should == 200
32
+ last_json['template']['preview'].should include('body')
33
+ end
34
+
35
+ it 'renders without a layout if no theme is present' do
36
+ request.env['HTTP_ACCEPT'] = 'application/json'
37
+ make_request attributes_for(:page, body: 'raw content')
38
+ response.status.should == 200
39
+ last_json['template']['preview'].should include('raw content')
40
+ end
41
+ end
42
+ end
43
+ end
@@ -4,5 +4,24 @@ module Landable
4
4
  describe Theme do
5
5
  it { should have_valid(:thumbnail_url).when(nil) }
6
6
  it { should be_a HasAssets }
7
+
8
+ describe '#most_used_theme' do
9
+ it 'returns the most used theme' do
10
+ t = create :theme
11
+ t2 = create :theme
12
+ t3 = create :theme
13
+ create :page, theme: t
14
+ create :page, theme: t
15
+ create :page, theme: t2
16
+ create :page, theme: t
17
+
18
+ Theme.most_used_on_pages.should == t
19
+ end
20
+
21
+ it 'return nil when there are no themes' do
22
+ Theme.destroy_all # Remove all themes!
23
+ Theme.most_used_on_pages.should be_nil
24
+ end
25
+ end
7
26
  end
8
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: landable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.1
4
+ version: 1.12.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Team Trogdor
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
11
+ date: 2015-01-14 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -463,6 +463,7 @@ files:
463
463
  - db/migrate/20140522202332_join_table_templates_pages.rb
464
464
  - db/migrate/20140602213937_path_response_time_view.rb
465
465
  - db/migrate/20141211200012_add_page_name_to_page.rb
466
+ - db/migrate/20141217171816_add_counter_for_themes_pages.rb
466
467
  - db/test/landable.access_tokens.sql
467
468
  - db/test/landable.assets.sql
468
469
  - db/test/landable.authors.sql
@@ -569,6 +570,7 @@ files:
569
570
  - spec/controllers/landable/api/page_revisions_controller_spec.rb
570
571
  - spec/controllers/landable/api/pages_controller_spec.rb
571
572
  - spec/controllers/landable/api/template_revisions_controller_spec.rb
573
+ - spec/controllers/landable/api/templates_controller_spec.rb
572
574
  - spec/controllers/landable/api_controller_spec.rb
573
575
  - spec/controllers/public/preview/page_revisions_controller_spec.rb
574
576
  - spec/controllers/public/preview/pages_controller_spec.rb
@@ -727,6 +729,7 @@ test_files:
727
729
  - spec/controllers/landable/api/page_revisions_controller_spec.rb
728
730
  - spec/controllers/landable/api/pages_controller_spec.rb
729
731
  - spec/controllers/landable/api/template_revisions_controller_spec.rb
732
+ - spec/controllers/landable/api/templates_controller_spec.rb
730
733
  - spec/controllers/landable/api_controller_spec.rb
731
734
  - spec/controllers/public/preview/page_revisions_controller_spec.rb
732
735
  - spec/controllers/public/preview/pages_controller_spec.rb