-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Custom page part title #2875
Custom page part title #2875
Conversation
@@ -591,15 +598,23 @@ var page_options = { | |||
$('#new_page_part_dialog').dialog('open'); | |||
}); | |||
|
|||
$('#new_page_part_title').on('keyup', function() { |
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 should be on "input" event. But it doesn't work for IE8 and IE9. But alternatively "propertychange" event can be used there.
Hi @parndt, I've updated this PR, could you review it and help me to understand why i've tests who fails? |
@bricesanchez because slug is required on PagePart but the test isn't setting it.. shouldn't the slug be able to default to |
Here's the validator and here's where it's needed |
Thanks @parndt, it works now!
it probably should but how ? |
Something like this: class PagePart
def slug
super || title.to_s.to_param
end
end |
Yes, i would like to use underscores instead of dashes. My method looks like this now : class PagePart
def slug
super || title.to_s.parameterize
end
end But with this i'm able to save a record with a title but a |
That's weird, is the title blank? |
Nope : <Refinery::PagePart id: 10, refinery_page_id: nil, slug: nil, body: nil, position: nil, created_at: "2015-03-16 02:48:58", updated_at: "2015-03-16 02:48:58", title: "er rew e 24 ^"> |
What about class PagePart
def slug
super.presence || title.to_s.parameterize.underscore.presence
end
end |
irb(main):001:0> p = Refinery::PagePart.new
=> #<Refinery::PagePart id: nil, refinery_page_id: nil, slug: nil, body: nil, position: nil, created_at: nil, updated_at: nil, title: nil>
irb(main):002:0> p.title = "esfefse f33\U+FFC3\U+FFA8"
=> "esfefse f33"
irb(main):003:0> p.save
(0.1ms) begin transaction
Refinery::PagePart Exists (0.1ms) SELECT 1 AS one FROM "refinery_page_parts" WHERE ("refinery_page_parts"."slug" = 'esfefse_f33' AND "refinery_page_parts"."refinery_page_id" IS NULL) LIMIT 1
SQL (0.2ms) INSERT INTO "refinery_page_parts" ("created_at", "title", "updated_at") VALUES (?, ?, ?) [["created_at", "2015-03-16 03:05:28.025965"], ["title", "esfefse f33"], ["updated_at", "2015-03-16 03:05:28.025965"]]
(4.4ms) commit transaction
=> true
irb(main):004:0> p = Refinery::PagePart.last
Refinery::PagePart Load (0.1ms) SELECT "refinery_page_parts".* FROM "refinery_page_parts" ORDER BY "refinery_page_parts"."id" DESC LIMIT 1
Refinery::PagePart::Translation Load (0.1ms) SELECT "refinery_page_part_translations".* FROM "refinery_page_part_translations" WHERE "refinery_page_part_translations"."refinery_page_part_id" = ? [["refinery_page_part_id", 11]]
=> #<Refinery::PagePart id: 11, refinery_page_id: nil, slug: nil, body: nil, position: nil, created_at: "2015-03-16 03:05:28", updated_at: "2015-03-16 03:05:28", title: "esfefse f33"> |
Or probably more accurately: class PagePart
before_validation :set_default_slug
private
def set_default_slug
self.slug = title.to_s.parameterize.underscore.presence if self.slug.blank?
end
end |
Now it works well and i understand the syntax 😄 |
@@ -312,11 +312,11 @@ def content_for?(part_title) | |||
# ::Refinery::Page.first.part_with_title(:body) | |||
# | |||
# Will return the Refinery::PagePart object with that title using the first page. | |||
def part_with_title(part_title) | |||
def part_with_slug(part_slug) |
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.
Can you please deprecate the old API, and update the documentation above this method to be correct?
Same thing needs to happen for content_for
, and content_for?
Normally we handle deprecations of public methods with the It also means you're going to have to handle the old API calls until e.g. version 3.1 so for def part_with_title(part_title)
Refinery.deprecate("Refinery::Page#part_with_title", when: "3.1", replacement: "part_with_slug")
part_with_slug(part_title.to_s.parameterize.underscore)
end Understand what I mean? |
Yep ! i will do that ASAP. 😄 |
2853d62
to
83cc38f
Compare
@simi are you happy with us maintaining this feature for the rest of time? |
Yes, I'm happy to maintain this for the rest of my poor life. But do we really need https://github.com/slav123/jquery-seo-url/blob/master/jquery.seourl.js included? If yes, why minificated? |
83cc38f
to
5b526f7
Compare
Seo url support all accents like (éèàçùî....), i've changed it for the unminificated version |
|
||
(function( $ ){ | ||
|
||
// protorype, and return string |
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.
prototype (patch sent - slav123/jquery-seo-url#1)
It is released as https://rubygems.org/gems/speakingurl-rails/versions/1.1.2 now. |
5b526f7
to
c7e9f39
Compare
I've made the changes :) |
@@ -34,11 +42,16 @@ def normalise_text_fields | |||
|
|||
private | |||
def parameterize(string) | |||
|
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.
✂️
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.
i will cut that, thanks.
What about to use new hash syntax? |
@simi, it will be great to use new hash syntax but may be in another refactor PR. |
c7e9f39
to
ca71f0f
Compare
@@ -10,3 +14,7 @@ | |||
:cancel_button_id => "new_page_part_cancel", | |||
:hide_delete => true %> | |||
</div> | |||
|
|||
<% content_for :after_javascript_libraries do %> | |||
<%= javascript_include_tag 'refinery/jquery.seourl' %> |
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.
Where does this file come from? I don't see it in the changeset.
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.
Sorry i've forgot to remove it since we doesn't use seourl, replaced by speaking-url
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 to add this dependency to refinerycms-core? Shouldn't it be a dependency of refinerycms-pages?
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.
good point, i move it to pages
ca71f0f
to
1c60cfa
Compare
@@ -4,7 +4,7 @@ class PagePartsController < ::Refinery::AdminController | |||
|
|||
def new | |||
render :partial => '/refinery/admin/pages/page_part_field', :locals => { | |||
:part => ::Refinery::PagePart.new(:title => params[:title], :body => params[:body]), | |||
:part => ::Refinery::PagePart.new(:title => params[:title], :slug => params[:slug], :body => params[:body]), |
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.
I think now this could just be:
:part => ::Refinery::PagePart.new(params.slice(:title, :slug, :body)),
1c60cfa
to
024915d
Compare
@@ -577,13 +577,17 @@ var page_options = { | |||
}, | |||
|
|||
page_part_dialog: function(){ | |||
var slugOptions = { | |||
separator: '_' |
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.
Isn't -
nicer?
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.
Agree. If nothing else, Google recommends hyphens over underscores. It used to be better for SEO although I'm not sure that's still the case.
Plus, it's marginally easier to type, matches domain restrictions, so it looks more URL-y (underscores are not allowed in domain names.)
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.
Sorry, i'm not agree.
We don't speak about the page slug but the page part slug.
The slug for the page part is never displayed as an entire page so Google will never see it.
When we call a page part in an html view, we write something like that :
<%= raw @page.content_for(:side_body) %>
not
<%= raw @page.content_for(:"side-body") %>
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.
Yeah this is for programmatical reference, nothing shown anywhere. I agree with @bricesanchez
00f84b9
to
040300c
Compare
9684bfd
to
47ef396
Compare
Fix specs with slug support Use params[:slug] for page_part_field render Validate presence of title in PagePart model Add slug locales in FR and EN Fix page_part_dialog JS Change new_page_part_save errors text Fix visual_editor_add_image specs with the adding of :slug param (thanks @parndt) slug should be able to default to title.to_param (thanks @parndt) Set default slug before validation Deprecate old api for title_matches? and part_with_title methods Add feature and deprecations in changelog Add speakingurl-rails gem Rewrite page part title to slug using speakingurl Credit @simi for page part title feature Move speakingurl dependency to pages Precompile speakingurl only if new page part config is enable Q&A of @parndt fix speaking url load fix permitted params for page parts
47ef396
to
1c6d736
Compare
Thanks @bricesanchez |
It's a working progress. This feature works but tests are failing on my computer.
I create this PR to share my progress and ask for inputs. I don't know if i'm doing the right things on controllers and models.
What do you think about that ?