-
-
Notifications
You must be signed in to change notification settings - Fork 152
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Getting a list of pages (for sitemaps, etc.) #193
Conversation
@@ -3,6 +3,7 @@ | |||
|
|||
require 'high_voltage/configuration' | |||
require 'high_voltage/constraints/root_route' | |||
require 'high_voltage/page_collector' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
I fixed the empty line, new line and "line too long" issues from Hound. Should I make the double-quoted string changes? Seemed like most of the repo is using single quotes. |
@@ -14,7 +14,8 @@ module Configuration | |||
:routes, | |||
) | |||
|
|||
attr_reader :action_caching, :action_caching_layout, :page_caching | |||
attr_reader :action_caching, :action_caching_layout, :page_caching, | |||
:page_ids |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do we need this attr_reader
if we are defining page_ids
on line 43?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah! You're right, not sure what I was thinking there.
Thanks for the pr @bentoncreation.
We're slowly in the process of moving towards double quotes. Instead of doing this via one big sweep we're just making changes as we go through. As such, any places that are touched we recommend moving to double quote usage. Some other thoughts: What do you think about extracting another class to represent a page (or view)? That way instead of having a few private methods in the Something along the lines of: if page.valid?
page_paths.push page.path
end |
Sure thing @dgalarza ! Thanks for the review. Okay, I'll follow Hound on double quotes, etc. (Although, I think it's wrong about 'detect' over 'find'. It seems to be thinking it's Enumerable, not the Find module.) A Page class makes sense. How would that relate to the PageFinder class? Are they overlapping at all? I want to make sure I get the right abstraction. |
I don't think that the new class would overlap with the |
Ok, cool. Also, I noticed in your sample code, you changed page_ids to page_paths. The original issue suggested page_ids as the interface...would you rather go with page_paths? |
Ah good question. I named it |
Does the following make sense to you? It seems like we're trying to make a distinction between file paths and URL paths. They could be different, since you can override the PageFinder with the Rot13PageFinder. To keep that distinction, we're calling the URL path a page_id. PageFinder says: give me a page_id and I'll find the file path. PageCollector is saying: give me a base file path and I'll return the page_ids for all the files I find there. |
Makes sense to me, 👍 |
Great, thanks! |
def page_ids | ||
page_ids = [] | ||
|
||
Find.find(content_path) do |file_path| |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Prefer detect
over find
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This method is getting a bit long and seems to be responsible for quite a bit. What do you think about extracting a private method for collecting Page objects and then using a select on that collection for valid ones.
Something like:
def page_ids
pages.select(&:valid?).map(&:id)
end
private
def pages
Find.find(content_path).map { |file_path| HighVoltage::Page.new(content_path, file_path) }
end
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yes, much nicer!
Hey @dgalarza, I've broken out the Page class we talked about and I think I have things ready for you to review. Let me know how this looks when you get the chance. Thanks! |
end | ||
|
||
it "is valid for a page" do | ||
expect(page(full_file_path("exists.html.erb")).valid?).to be true |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider using:
expect(page(full_file_path("exists.html.erb"))).to be_valid
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's also a little hard to follow along with the number of nested method calls and their opening / closing parens. What do you think about making it easier to read with something like:
page = page(full_file_path("exists.html.erb"))
expect(page).to be_valid
throughout.
@bentoncreation this is looking really good. Just a few more stylistic tweaks and I think this will be ready to merge soon. Thanks for keeping up with it @bentoncreation. |
@dgalarza Hey, thanks for the guidance/patience! :) I'm going to try to make your recommended fixes this morning. |
Awesome stuff @bentoncreation. Looks good to me. Would you mind squashing to prep this for a merge? Otherwise I can go ahead and do so. Also, it might be useful to add something in the README about this and it's applicable usage. |
👍 nice work @bentoncreation. I'm not familiar with this codebase but I CRed and LGTM. Nice! |
Thanks, @dgalarza! I'll work on a README update shortly. Thanks, @aguynamedben! |
Hey @dgalarza, can you let me know if the README update looks ok? |
Looks good to me @bentoncreation |
@dgalarza Okay, I think I squashed it right. That was my first time doing an interactive rebase. :) Let me know if anything else is needed. |
Thanks again for the hard work on this @bentoncreation. I'll put out a release with this in it later in the week. 👍 |
Getting a list of pages (for sitemaps, etc.)
Sounds good, thanks! |
Here's my take on getting a list of High Voltage pages for building sitemaps, based on this issue: #123
If you're using the sitemap_generator gem, you could do something like this in your config: