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

Custom page part title #2875

Merged
merged 2 commits into from
Jul 18, 2015
Merged

Custom page part title #2875

merged 2 commits into from
Jul 18, 2015

Conversation

bricesanchez
Copy link
Member

It's a working progress. This feature works but tests are failing on my computer.

company_name_-_refinery-page-part-slug

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 ?

@@ -591,15 +598,23 @@ var page_options = {
$('#new_page_part_dialog').dialog('open');
});

$('#new_page_part_title').on('keyup', function() {
Copy link
Member

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.

@bricesanchez
Copy link
Member Author

a98c0d74d7e1b8163a57c9ada685d9e4 1

Hi @parndt,

I've updated this PR, could you review it and help me to understand why i've tests who fails?

@parndt
Copy link
Member

parndt commented Mar 14, 2015

@bricesanchez because slug is required on PagePart but the test isn't setting it.. shouldn't the slug be able to default to title.to_param?

@parndt
Copy link
Member

parndt commented Mar 14, 2015

Here's the validator and here's where it's needed

@bricesanchez
Copy link
Member Author

Thanks @parndt, it works now!

shouldn't the slug be able to default to title.to_param?

it probably should but how ?

@parndt
Copy link
Member

parndt commented Mar 15, 2015

Something like this:

class PagePart
  def slug
    super || title.to_s.to_param
  end
end

@bricesanchez
Copy link
Member Author

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 nil slug

@parndt
Copy link
Member

parndt commented Mar 16, 2015

That's weird, is the title blank?

@bricesanchez
Copy link
Member Author

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 ^">

@parndt
Copy link
Member

parndt commented Mar 16, 2015

What about

class PagePart
  def slug
    super.presence || title.to_s.parameterize.underscore.presence
  end
end

@bricesanchez
Copy link
Member Author

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">

@parndt
Copy link
Member

parndt commented Mar 16, 2015

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

@bricesanchez
Copy link
Member Author

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)
Copy link
Member

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?

@parndt
Copy link
Member

parndt commented Mar 16, 2015

Normally we handle deprecations of public methods with the Refinery.deprecate method. You should find examples in the codebase already for things that are changing from 2.1 -> 3.0

It also means you're going to have to handle the old API calls until e.g. version 3.1 so for part_with_title that would look something like this (so that it actually calls the new API underneath with the right argument):

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?

@bricesanchez
Copy link
Member Author

Yep ! i will do that ASAP. 😄

@bricesanchez bricesanchez self-assigned this Apr 1, 2015
@bricesanchez bricesanchez added this to the 3.0 milestone Apr 1, 2015
@bricesanchez bricesanchez force-pushed the page-part-title branch 2 times, most recently from 2853d62 to 83cc38f Compare April 15, 2015 03:06
@bricesanchez
Copy link
Member Author

output_ebnhpj

@parndt
Copy link
Member

parndt commented Apr 16, 2015

@simi are you happy with us maintaining this feature for the rest of time?

@simi
Copy link
Member

simi commented Apr 16, 2015

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?

@bricesanchez
Copy link
Member Author

Seo url support all accents like (éèàçùî....), i've changed it for the unminificated version


(function( $ ){

// protorype, and return string
Copy link
Member

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)

@simi
Copy link
Member

simi commented Apr 17, 2015

It is released as https://rubygems.org/gems/speakingurl-rails/versions/1.1.2 now.

@bricesanchez
Copy link
Member Author

I've made the changes :)

@@ -34,11 +42,16 @@ def normalise_text_fields

private
def parameterize(string)

Copy link
Member

Choose a reason for hiding this comment

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

✂️

Copy link
Member Author

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.

@simi
Copy link
Member

simi commented Apr 21, 2015

What about to use new hash syntax?

@bricesanchez
Copy link
Member Author

@simi, it will be great to use new hash syntax but may be in another refactor PR.

@@ -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' %>
Copy link
Member

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.

Copy link
Member Author

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

Copy link
Member

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?

Copy link
Member Author

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

@@ -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]),
Copy link
Member

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)),

@@ -577,13 +577,17 @@ var page_options = {
},

page_part_dialog: function(){
var slugOptions = {
separator: '_'
Copy link
Member

Choose a reason for hiding this comment

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

Isn't - nicer?

Copy link
Contributor

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

Copy link
Member Author

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") %>

Copy link
Member

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

@bricesanchez bricesanchez force-pushed the page-part-title branch 2 times, most recently from 00f84b9 to 040300c Compare May 2, 2015 04:31
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
parndt added a commit that referenced this pull request Jul 18, 2015
@parndt parndt merged commit 6396c1a into refinery:master Jul 18, 2015
@parndt
Copy link
Member

parndt commented Jul 18, 2015

Thanks @bricesanchez

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