Skip to content
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

Merged
merged 1 commit into from
Jun 23, 2015

Conversation

jeremysmithco
Copy link
Contributor

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:

HighVoltage.page_ids.each do |page|
  add page, changefreq: 'monthly'
end

@@ -3,6 +3,7 @@

require 'high_voltage/configuration'
require 'high_voltage/constraints/root_route'
require 'high_voltage/page_collector'

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.

@jeremysmithco
Copy link
Contributor Author

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
Copy link
Contributor

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?

Copy link
Contributor Author

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.

@dgalarza
Copy link
Contributor

Thanks for the pr @bentoncreation.

Should I make the double-quoted string changes? Seemed like most of the repo is using single quotes

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 PageCollector class that need the same argument passed around, it could be contained within this new object.

Something along the lines of:

if page.valid?
  page_paths.push page.path
end

@jeremysmithco
Copy link
Contributor Author

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.

@dgalarza
Copy link
Contributor

I don't think that the new class would overlap with the PageFinder class since PageFinder is specifically responsible for finding a given static page based off an ID.

@jeremysmithco
Copy link
Contributor Author

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?

@dgalarza
Copy link
Contributor

Ah good question. I named it page_paths in my examples since it looked like you were collecting the path to a page with url_path. It feels like a better name imo however I don't feel to strongly about it if you feel otherwise.

@jeremysmithco
Copy link
Contributor Author

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.

@dgalarza
Copy link
Contributor

Makes sense to me, 👍

@jeremysmithco
Copy link
Contributor Author

Great, thanks!

def page_ids
page_ids = []

Find.find(content_path) do |file_path|

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer detect over find.

Copy link
Contributor

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

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah yes, much nicer!

@jeremysmithco
Copy link
Contributor Author

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
Copy link
Contributor

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

Copy link
Contributor

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.

@dgalarza
Copy link
Contributor

@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.

@jeremysmithco
Copy link
Contributor Author

@dgalarza Hey, thanks for the guidance/patience! :) I'm going to try to make your recommended fixes this morning.

@dgalarza
Copy link
Contributor

dgalarza commented Jun 5, 2015

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.

@aguynamedben
Copy link

👍 nice work @bentoncreation. I'm not familiar with this codebase but I CRed and LGTM. Nice!

@jeremysmithco
Copy link
Contributor Author

Thanks, @dgalarza! I'll work on a README update shortly.

Thanks, @aguynamedben!

@jeremysmithco
Copy link
Contributor Author

Hey @dgalarza, can you let me know if the README update looks ok?

@dgalarza
Copy link
Contributor

Looks good to me @bentoncreation

@jeremysmithco
Copy link
Contributor Author

@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.

@dgalarza
Copy link
Contributor

Thanks again for the hard work on this @bentoncreation. I'll put out a release with this in it later in the week. 👍

dgalarza added a commit that referenced this pull request Jun 23, 2015
Getting a list of pages (for sitemaps, etc.)
@dgalarza dgalarza merged commit 1eba606 into thoughtbot:master Jun 23, 2015
@jeremysmithco
Copy link
Contributor Author

Sounds good, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants