-
Notifications
You must be signed in to change notification settings - Fork 299
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
Adding possibility to change pagination message by config file #324
Adding possibility to change pagination message by config file #324
Conversation
dc203ab
to
e1e87e9
Compare
e97cdef
to
5194e6b
Compare
I added information about this change to docs/advanced-usage.md |
9c5aedf
to
692f467
Compare
I am working on tests and changes for build. |
I am working on tests. It takes some time. I will update this PR. |
I have problem with tests for this change (Sorry, I am not Ruby developer. I just backported my own change for my site from local repository, because it looks like helpful for other users). Looks like I need something like in file spec/jekyll_seo_tag/drop_spec.rb
for testing page_number function. Could you please help\advise with tests for this change? |
@AlekseySpiridonov Testing this particular change with RSpec appears to be hard because context "pagination" do
let(:context) do
make_context(
{ :page => page, :site => site },
"paginator" => { "page" => 2, "total_pages" => 10 }
)
end
it "renders the correct page number" do
expect(subject.send(:page_number)).to eq("Page 2 of 10 for ")
end
end The above will pass for the default message. Once that's done, you need to test for the custom message as well: context "pagination" do
let(:context) do
make_context(
{ :page => page, :site => site },
"paginator" => { "page" => 2, "total_pages" => 10 }
)
end
it "renders the correct page number" do
expect(subject.send(:page_number)).to eq("Page 2 of 10 for ")
end
# nested context
context "with custom pagination message" do
let(:config) { ... }
it "" do
end
end |
@ashmaroli I added tests but it always failed. Commit - fbecf19 Logs:
Could you please check my commit? |
@AlekseySpiridonov I knew it would fail. That's the beauty of test-driven-development. The fact is that while your implementation works, technically it is not the proper way.
So, the def page_number
return unless @context["paginator"] && @context["paginator"]["page"]
current = @context["paginator"]["page"]
total = @context["paginator"]["total_pages"]
paginator_message = site["paginator_message"] || "Page %<current>s of %<total>s for "
format(paginator_message, :current => current, :total => total) if current > 1
end
There's one other teeny mistake in your test as well: your custom-message context is not nested under the default-message context. Perhaps, my example wasn't clear enough. context "..." do
...
context "..." do
...
end
end So, the test will be something like: context "pagination" do
let(:context) do
...
end
it "renders.." do
...
end
# nested context
context "with custom message..." do
let(:config) { { "paginator_message" => "%<current>s of %<total>s" } }
it "renders..." do
...
end
end
end Now what you have to do is:
|
6266ea5
to
95a80e3
Compare
Default message can by overriten by "paginator_message" parameter in _config.yml
95a80e3
to
39269ed
Compare
@ashmaroli thank you so much. |
|
@jekyll/plugin-core Should we nest the |
Would it make sense to change the message (in all cases) to "Page ___ / ____" and then just allow "page" to be localized, rather than going down the path of string interpolation? If we are going that route, would a sprintf style |
@benbalter The current approach uses |
@ashmaroli I think I was looking at an outdated diff. Sorry for the noise and thanks for taking the time to further explain. 👍 |
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 nice to be able to localize messages.
I wish every plugin would use a proper namespace though instead of adding another global config key. Maybe we can revisit all current settings under a common key in next major version?
Do you need some additional changes from my side or we are waiting review? |
I need this change. +1 for merge this pool request. |
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.
Yay for string translations.
@jekyllbot: merge +minor |
Thanks a lot! |
Default message can by overriten by "paginator_message" parameter in _config.yml
This change allows you to change messages for localize the site to other languages.