high_voltage 2.3.0 → 2.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile.lock +4 -1
- data/NEWS.md +5 -0
- data/README.md +12 -1
- data/lib/high_voltage.rb +2 -0
- data/lib/high_voltage/configuration.rb +17 -3
- data/lib/high_voltage/page.rb +44 -0
- data/lib/high_voltage/page_collector.rb +23 -0
- data/lib/high_voltage/page_finder.rb +5 -1
- data/lib/high_voltage/version.rb +1 -1
- data/spec/fake_app.rb +1 -4
- data/spec/fixtures/app/views/pages/_partial.html.erb +1 -0
- data/spec/fixtures/app/views/pages/text.txt.erb +1 -0
- data/spec/high_voltage/configuration_spec.rb +66 -21
- data/spec/high_voltage/page_collector_spec.rb +36 -0
- data/spec/high_voltage/page_finder_spec.rb +4 -0
- data/spec/high_voltage/page_spec.rb +65 -0
- metadata +12 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 56801929181e1df1b48361637a33d0e49431827f
|
4
|
+
data.tar.gz: e5e8b40606fd4863b423cd682ae3bc0426d11af2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7baeff6c124d223bbe28962a65ad6fcfdddc7a505c15dd63c6fb0e52530508809c03acee1bc37bd10f65e36aea1d430ef714d00518c38370941d9fc397eaa3f6
|
7
|
+
data.tar.gz: c9dd536f08b5ce08cf6ae7a479e3e4f99556d117611656c7ce795843046627f87da726bb5a83163a6a4131968a8081fbc637b89015d76f41daad9c4fab79d167
|
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/NEWS.md
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
New for 2.4.0
|
2
|
+
+ Retrieve a list of available static pages via `HighVoltage.page_ids`.
|
3
|
+
+ Properly handle page ids which are blank when being sanitized.
|
4
|
+
+ Only provide deprecation warnings around caching when caching is enabled.
|
5
|
+
|
1
6
|
New for 2.3.0:
|
2
7
|
+ Ruby 2.2 and Rails 4.2 testing
|
3
8
|
+ Raise InvalidPageIdError when visiting a page with invalid characters
|
data/README.md
CHANGED
@@ -15,7 +15,7 @@ Yeah, like "About us", "Directions", marketing pages, etc.
|
|
15
15
|
Include in your Gemfile:
|
16
16
|
|
17
17
|
```ruby
|
18
|
-
gem 'high_voltage', '~> 2.3.0
|
18
|
+
gem 'high_voltage', '~> 2.3.0'
|
19
19
|
```
|
20
20
|
|
21
21
|
For Rails versions prior to 3.0, use the 0.9.2 tag of high_voltage:
|
@@ -43,6 +43,17 @@ link_to 'Q4 Reports', page_path('about/corporate/policies/HR/en_US/biz/sales/Qua
|
|
43
43
|
|
44
44
|
Bam.
|
45
45
|
|
46
|
+
You can also get a list of your static pages by calling `HighVoltage.page_ids`
|
47
|
+
This might be useful if you need to build a sitemap. For example, if you are
|
48
|
+
using the [sitemap_generator](https://github.com/kjvarga/sitemap_generator) gem,
|
49
|
+
you could add something like this to your sitemap config file:
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
HighVoltage.page_ids.each do |page|
|
53
|
+
add page, changefreq: 'monthly'
|
54
|
+
end
|
55
|
+
```
|
56
|
+
|
46
57
|
## Configuration
|
47
58
|
|
48
59
|
#### Routing overview
|
data/lib/high_voltage.rb
CHANGED
@@ -3,6 +3,8 @@ require 'active_support/core_ext/module/attribute_accessors'
|
|
3
3
|
|
4
4
|
require 'high_voltage/configuration'
|
5
5
|
require 'high_voltage/constraints/root_route'
|
6
|
+
require "high_voltage/page"
|
7
|
+
require "high_voltage/page_collector"
|
6
8
|
require 'high_voltage/page_finder'
|
7
9
|
require 'high_voltage/route_drawers/default'
|
8
10
|
require 'high_voltage/route_drawers/root'
|
@@ -25,20 +25,34 @@ module HighVoltage
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def action_caching=(value)
|
28
|
-
|
28
|
+
unless value == false
|
29
|
+
ActiveSupport::Deprecation.warn(CACHING_DEPRECATION_WARNING)
|
30
|
+
end
|
29
31
|
@action_caching = value
|
30
32
|
end
|
31
33
|
|
32
34
|
def action_caching_layout=(value)
|
33
|
-
|
35
|
+
unless value == false
|
36
|
+
ActiveSupport::Deprecation.warn(CACHING_DEPRECATION_WARNING)
|
37
|
+
end
|
34
38
|
@action_caching_layout = value
|
35
39
|
end
|
36
40
|
|
37
41
|
def page_caching=(value)
|
38
|
-
|
42
|
+
unless value == false
|
43
|
+
ActiveSupport::Deprecation.warn(CACHING_DEPRECATION_WARNING)
|
44
|
+
end
|
39
45
|
@page_caching = value
|
40
46
|
end
|
41
47
|
|
48
|
+
def page_ids
|
49
|
+
HighVoltage::PageCollector.new(HighVoltage.full_path).page_ids
|
50
|
+
end
|
51
|
+
|
52
|
+
def full_path
|
53
|
+
Rails.root.join("app", "views", HighVoltage.content_path)
|
54
|
+
end
|
55
|
+
|
42
56
|
def set_default_configuration
|
43
57
|
@action_caching = false
|
44
58
|
@action_caching_layout = true
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module HighVoltage
|
2
|
+
class Page
|
3
|
+
attr_reader :content_path, :file_path
|
4
|
+
|
5
|
+
def initialize(content_path, file_path)
|
6
|
+
@content_path = content_path
|
7
|
+
@file_path = file_path
|
8
|
+
end
|
9
|
+
|
10
|
+
def id
|
11
|
+
file_path.gsub(content_path, "").gsub(html_file_pattern, "")
|
12
|
+
end
|
13
|
+
|
14
|
+
def valid?
|
15
|
+
exists? && file_in_content_path? && !directory? && !partial? && html?
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def exists?
|
21
|
+
File.exists?(file_path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def file_in_content_path?
|
25
|
+
file_path.start_with?(content_path)
|
26
|
+
end
|
27
|
+
|
28
|
+
def directory?
|
29
|
+
FileTest.directory?(file_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
def partial?
|
33
|
+
File.basename(file_path).first == "_"
|
34
|
+
end
|
35
|
+
|
36
|
+
def html?
|
37
|
+
!file_path.match(html_file_pattern).nil?
|
38
|
+
end
|
39
|
+
|
40
|
+
def html_file_pattern
|
41
|
+
/\.(html)(\.[a-z]+)?$/
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module HighVoltage
|
2
|
+
require "find"
|
3
|
+
|
4
|
+
class PageCollector
|
5
|
+
attr_reader :content_path
|
6
|
+
|
7
|
+
def initialize(content_path)
|
8
|
+
@content_path = content_path.to_s
|
9
|
+
end
|
10
|
+
|
11
|
+
def page_ids
|
12
|
+
pages.select(&:valid?).map(&:id)
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
|
17
|
+
def pages
|
18
|
+
Find.find(content_path).map do |file_path|
|
19
|
+
HighVoltage::Page.new(content_path, file_path)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -27,7 +27,11 @@ module HighVoltage
|
|
27
27
|
|
28
28
|
def clean_path
|
29
29
|
path = Pathname.new("/#{clean_id}")
|
30
|
-
path.cleanpath.to_s[1..-1]
|
30
|
+
path.cleanpath.to_s[1..-1].tap do |p|
|
31
|
+
if p.blank?
|
32
|
+
raise InvalidPageIdError.new "Invalid page id: #{@page_id}"
|
33
|
+
end
|
34
|
+
end
|
31
35
|
end
|
32
36
|
|
33
37
|
def clean_id
|
data/lib/high_voltage/version.rb
CHANGED
data/spec/fake_app.rb
CHANGED
@@ -6,13 +6,10 @@ end
|
|
6
6
|
module Dummy
|
7
7
|
class Application < Rails::Application
|
8
8
|
config.secret_key_base = "test"
|
9
|
-
config.paths["public"] = ["spec/fixtures/public"]
|
10
|
-
config.paths["config/routes.rb"] = ["spec/fixtures/config/routes.rb"]
|
11
|
-
config.paths["app/views"] = ["spec/fixtures/app/views"]
|
12
|
-
config.paths["app/controllers"] = ["spec/support/app/controllers"]
|
13
9
|
config.eager_load = false
|
14
10
|
config.action_controller.perform_caching = true
|
15
11
|
config.action_controller.cache_store = :memory_store
|
12
|
+
config.root = "spec/fixtures"
|
16
13
|
end
|
17
14
|
end
|
18
15
|
Dummy::Application.initialize!
|
@@ -0,0 +1 @@
|
|
1
|
+
partial
|
@@ -0,0 +1 @@
|
|
1
|
+
text page
|
@@ -35,42 +35,87 @@ describe HighVoltage::Configuration do
|
|
35
35
|
it { expect(HighVoltage.routes).to eq config_value }
|
36
36
|
end
|
37
37
|
|
38
|
-
describe
|
39
|
-
|
40
|
-
|
38
|
+
describe "#action_caching" do
|
39
|
+
context "action caching is enabled" do
|
40
|
+
it 'displays a deprecation warning' do
|
41
|
+
allow(ActiveSupport::Deprecation).to receive(:warn)
|
41
42
|
|
42
|
-
|
43
|
-
|
43
|
+
HighVoltage.configure do |config|
|
44
|
+
config.action_caching = true
|
45
|
+
end
|
46
|
+
|
47
|
+
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
48
|
+
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
44
49
|
end
|
50
|
+
end
|
51
|
+
|
52
|
+
context "action caching is disabled" do
|
53
|
+
it 'does not display a deprecation warning' do
|
54
|
+
allow(ActiveSupport::Deprecation).to receive(:warn)
|
55
|
+
|
56
|
+
HighVoltage.configure do |config|
|
57
|
+
config.action_caching = false
|
58
|
+
end
|
45
59
|
|
46
|
-
|
47
|
-
|
60
|
+
expect(ActiveSupport::Deprecation).not_to have_received(:warn)
|
61
|
+
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
62
|
+
end
|
48
63
|
end
|
49
64
|
end
|
50
65
|
|
51
|
-
describe
|
52
|
-
|
53
|
-
|
66
|
+
describe "#action_caching_layout" do
|
67
|
+
context "action caching layout is enabled" do
|
68
|
+
it 'displays a deprecation warning' do
|
69
|
+
allow(ActiveSupport::Deprecation).to receive(:warn)
|
54
70
|
|
55
|
-
|
56
|
-
|
71
|
+
HighVoltage.configure do |config|
|
72
|
+
config.action_caching_layout = true
|
73
|
+
end
|
74
|
+
|
75
|
+
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
76
|
+
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
57
77
|
end
|
78
|
+
end
|
58
79
|
|
59
|
-
|
60
|
-
|
80
|
+
context "action caching layout is disabled" do
|
81
|
+
it "does not display a deprecation warning" do
|
82
|
+
allow(ActiveSupport::Deprecation).to receive(:warn)
|
83
|
+
|
84
|
+
HighVoltage.configure do |config|
|
85
|
+
config.action_caching_layout = false
|
86
|
+
end
|
87
|
+
|
88
|
+
expect(ActiveSupport::Deprecation).not_to have_received(:warn)
|
89
|
+
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
90
|
+
end
|
61
91
|
end
|
62
92
|
end
|
63
93
|
|
64
|
-
describe
|
65
|
-
|
66
|
-
|
94
|
+
describe "#page_caching" do
|
95
|
+
context "page caching is enabled" do
|
96
|
+
it "displays a deprecation warning" do
|
97
|
+
allow(ActiveSupport::Deprecation).to receive(:warn)
|
67
98
|
|
68
|
-
|
69
|
-
|
99
|
+
HighVoltage.configure do |config|
|
100
|
+
config.page_caching = true
|
101
|
+
end
|
102
|
+
|
103
|
+
expect(ActiveSupport::Deprecation).to have_received(:warn)
|
104
|
+
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
70
105
|
end
|
106
|
+
end
|
107
|
+
|
108
|
+
context "page caching is disbled" do
|
109
|
+
it "does not display a deprecation warning" do
|
110
|
+
allow(ActiveSupport::Deprecation).to receive(:warn)
|
71
111
|
|
72
|
-
|
73
|
-
|
112
|
+
HighVoltage.configure do |config|
|
113
|
+
config.page_caching = false
|
114
|
+
end
|
115
|
+
|
116
|
+
expect(ActiveSupport::Deprecation).not_to have_received(:warn)
|
117
|
+
.with(HighVoltage::Configuration::CACHING_DEPRECATION_WARNING)
|
118
|
+
end
|
74
119
|
end
|
75
120
|
end
|
76
121
|
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe HighVoltage::PageCollector do
|
4
|
+
it "produces an array of all page_ids under pages/" do
|
5
|
+
expect(HighVoltage.page_ids).to eq [
|
6
|
+
"also_dir/also_nested",
|
7
|
+
"also_exists",
|
8
|
+
"also_exists_but_references_nonexistent_partial",
|
9
|
+
"dir/nested",
|
10
|
+
"exists",
|
11
|
+
"exists_but_references_nonexistent_partial",
|
12
|
+
"rot13"
|
13
|
+
]
|
14
|
+
end
|
15
|
+
|
16
|
+
it "produces an array of all page_ids under other_pages/" do
|
17
|
+
with_content_path("other_pages/") do
|
18
|
+
expect(HighVoltage.page_ids).to eq [
|
19
|
+
"also_dir/also_nested",
|
20
|
+
"also_exists",
|
21
|
+
"also_exists_but_references_nonexistent_partial",
|
22
|
+
]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def with_content_path(path)
|
29
|
+
original_content_path = HighVoltage.content_path
|
30
|
+
HighVoltage.content_path = path
|
31
|
+
|
32
|
+
yield
|
33
|
+
|
34
|
+
HighVoltage.content_path = original_content_path
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,65 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe HighVoltage::Page do
|
4
|
+
it "produces the id for a page" do
|
5
|
+
page = page(full_file_path("exists.html.erb"))
|
6
|
+
|
7
|
+
expect(page.id).to eq "exists"
|
8
|
+
end
|
9
|
+
|
10
|
+
it "produces the id for a page in a subdirectory" do
|
11
|
+
page = page(full_file_path("dir/nested.html.erb"))
|
12
|
+
|
13
|
+
expect(page.id).to eq "dir/nested"
|
14
|
+
end
|
15
|
+
|
16
|
+
it "is valid for a page" do
|
17
|
+
page = page(full_file_path("exists.html.erb"))
|
18
|
+
|
19
|
+
expect(page).to be_valid
|
20
|
+
end
|
21
|
+
|
22
|
+
it "is valid for a page in a subdirectory" do
|
23
|
+
page = page(full_file_path("dir/nested.html.erb"))
|
24
|
+
|
25
|
+
expect(page).to be_valid
|
26
|
+
end
|
27
|
+
|
28
|
+
it "is invalid for a directory" do
|
29
|
+
page = page(full_file_path("dir"))
|
30
|
+
|
31
|
+
expect(page).to_not be_valid
|
32
|
+
end
|
33
|
+
|
34
|
+
it "is invalid for a partial" do
|
35
|
+
page = page(full_file_path("_partial.html.erb"))
|
36
|
+
|
37
|
+
expect(page).to_not be_valid
|
38
|
+
end
|
39
|
+
|
40
|
+
it "is invalid for a non-existent page" do
|
41
|
+
page = page(full_file_path("nonexistent.html.erb"))
|
42
|
+
|
43
|
+
expect(page).to_not be_valid
|
44
|
+
end
|
45
|
+
|
46
|
+
it "is invalid for a text page" do
|
47
|
+
page = page(full_file_path("text.txt.erb"))
|
48
|
+
|
49
|
+
expect(page).to_not be_valid
|
50
|
+
end
|
51
|
+
|
52
|
+
private
|
53
|
+
|
54
|
+
def full_content_path
|
55
|
+
HighVoltage.full_path.to_s
|
56
|
+
end
|
57
|
+
|
58
|
+
def page(file_path)
|
59
|
+
HighVoltage::Page.new(full_content_path, file_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
def full_file_path(file_path)
|
63
|
+
"#{full_content_path}#{file_path}"
|
64
|
+
end
|
65
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: high_voltage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Jankowski
|
@@ -16,7 +16,7 @@ authors:
|
|
16
16
|
autorequire:
|
17
17
|
bindir: bin
|
18
18
|
cert_chain: []
|
19
|
-
date: 2015-
|
19
|
+
date: 2015-07-17 00:00:00.000000000 Z
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
22
22
|
name: activesupport
|
@@ -88,6 +88,8 @@ files:
|
|
88
88
|
- lib/high_voltage/configuration.rb
|
89
89
|
- lib/high_voltage/constraints/root_route.rb
|
90
90
|
- lib/high_voltage/engine.rb
|
91
|
+
- lib/high_voltage/page.rb
|
92
|
+
- lib/high_voltage/page_collector.rb
|
91
93
|
- lib/high_voltage/page_finder.rb
|
92
94
|
- lib/high_voltage/route_drawers/default.rb
|
93
95
|
- lib/high_voltage/route_drawers/root.rb
|
@@ -105,6 +107,7 @@ files:
|
|
105
107
|
- spec/fixtures/app/views/other_pages/also_dir/also_nested.html.erb
|
106
108
|
- spec/fixtures/app/views/other_pages/also_exists.html.erb
|
107
109
|
- spec/fixtures/app/views/other_pages/also_exists_but_references_nonexistent_partial.html.erb
|
110
|
+
- spec/fixtures/app/views/pages/_partial.html.erb
|
108
111
|
- spec/fixtures/app/views/pages/also_dir/also_nested.html.erb
|
109
112
|
- spec/fixtures/app/views/pages/also_exists.html.erb
|
110
113
|
- spec/fixtures/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb
|
@@ -112,11 +115,14 @@ files:
|
|
112
115
|
- spec/fixtures/app/views/pages/exists.html.erb
|
113
116
|
- spec/fixtures/app/views/pages/exists_but_references_nonexistent_partial.html.erb
|
114
117
|
- spec/fixtures/app/views/pages/rot13.html.erb
|
118
|
+
- spec/fixtures/app/views/pages/text.txt.erb
|
115
119
|
- spec/fixtures/config/database.yml
|
116
120
|
- spec/fixtures/config/routes.rb
|
117
121
|
- spec/fixtures/public/pages/exists.html
|
118
122
|
- spec/high_voltage/configuration_spec.rb
|
123
|
+
- spec/high_voltage/page_collector_spec.rb
|
119
124
|
- spec/high_voltage/page_finder_spec.rb
|
125
|
+
- spec/high_voltage/page_spec.rb
|
120
126
|
- spec/high_voltage_spec.rb
|
121
127
|
- spec/integration/navigation_spec.rb
|
122
128
|
- spec/minimal_spec_helper.rb
|
@@ -163,6 +169,7 @@ test_files:
|
|
163
169
|
- spec/fixtures/app/views/other_pages/also_dir/also_nested.html.erb
|
164
170
|
- spec/fixtures/app/views/other_pages/also_exists.html.erb
|
165
171
|
- spec/fixtures/app/views/other_pages/also_exists_but_references_nonexistent_partial.html.erb
|
172
|
+
- spec/fixtures/app/views/pages/_partial.html.erb
|
166
173
|
- spec/fixtures/app/views/pages/also_dir/also_nested.html.erb
|
167
174
|
- spec/fixtures/app/views/pages/also_exists.html.erb
|
168
175
|
- spec/fixtures/app/views/pages/also_exists_but_references_nonexistent_partial.html.erb
|
@@ -170,11 +177,14 @@ test_files:
|
|
170
177
|
- spec/fixtures/app/views/pages/exists.html.erb
|
171
178
|
- spec/fixtures/app/views/pages/exists_but_references_nonexistent_partial.html.erb
|
172
179
|
- spec/fixtures/app/views/pages/rot13.html.erb
|
180
|
+
- spec/fixtures/app/views/pages/text.txt.erb
|
173
181
|
- spec/fixtures/config/database.yml
|
174
182
|
- spec/fixtures/config/routes.rb
|
175
183
|
- spec/fixtures/public/pages/exists.html
|
176
184
|
- spec/high_voltage/configuration_spec.rb
|
185
|
+
- spec/high_voltage/page_collector_spec.rb
|
177
186
|
- spec/high_voltage/page_finder_spec.rb
|
187
|
+
- spec/high_voltage/page_spec.rb
|
178
188
|
- spec/high_voltage_spec.rb
|
179
189
|
- spec/integration/navigation_spec.rb
|
180
190
|
- spec/minimal_spec_helper.rb
|