Skip to content

Enhance position option with :append and :prepend options to inject code at start or end of head or body tags#36

Closed
salimhb wants to merge 7 commits into
masterfrom
exact_position
Closed

Enhance position option with :append and :prepend options to inject code at start or end of head or body tags#36
salimhb wants to merge 7 commits into
masterfrom
exact_position

Conversation

@salimhb

@salimhb salimhb commented May 6, 2015

Copy link
Copy Markdown
Member

No description provided.

Comment thread spec/tracker/tracker_spec.rb Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

hm... I mean it's not critical but I don't really like the semantics here. With your change position is not precise anymore. Maybe we should call it container or something, and let the position be opening/closing ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Yeah. I wasn't sure about the semantics here either. But I wanted to just get this PR out to get feedback about this.
:container/:position actually sound better. Thanks :)

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

done now with container_tag and container_position. I avoided changing the position attribute at first to avoid changing it everywhere.

@salimhb salimhb changed the title [wip] add exact_position option to allow injecting handlers after the opening of the :position tag add :container_position option to allow injecting handlers after the opening of the :container_tag May 6, 2015
@jhilden

jhilden commented May 6, 2015

Copy link
Copy Markdown
Contributor

I find the the wording with :opening and :closing not 100% ideal. What about using jquery as a well known inspiration and using :prepend and :append instead?

@DonSchado

Copy link
Copy Markdown
Collaborator

👍 for prepend/append

@salimhb

salimhb commented May 6, 2015

Copy link
Copy Markdown
Member Author

That also sounds good. Getting more inspired by jquery, I was also thinking of using inside to specify the head or body tag. So it would be:

self.position_inside = :head # or :body
self.position_insert = :append # or :prepend

Comment thread lib/rack/tracker.rb Outdated

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I mean, yes it's a first draft. But what I totally dislike about this code is the responsibility of the tracker.
It was not optimal before, but now it's even worse. Why do the tracker need to ask the handler about his position, to again decide which "message" to send to it again.... weird. The handler should take care of all that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

this inject method gets the response, changes it, and returns it.
If we want to move this inject into the handlers, then we would need to pass the response again to an inject method inside each handler. Doesn't that make it slower and more difficult to understand what is happening? It would also allow the handler to change whatever else it likes in the response!

Another way I could think of doing this is to group handlers according to their container_tag and container_position, render them together, and then gsub once for each group. What do you think about that?

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

I'm with you on the response.gsub part,... but I think the behavior what comes first/last (the position) should be inside of the handler.

btw. </#{handler.container_tag}> doesn't match elements with attributes right?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

Then what do you think about the grouping idea?

And yeah, good catch, that affects the code 2 lines below! I'll change it and add a spec for that.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

a17b6c0 should take care of the element with attributes issue

@DonSchado

Copy link
Copy Markdown
Collaborator

hm position_inside/position_insert sounds weird too imho.

why not give it a method and let it look more like a DSL?

position body: :prepend

@salimhb

salimhb commented May 6, 2015

Copy link
Copy Markdown
Member Author

I discarded the idea of using a hash at the beginning, but this way it looks actually nice.

@kangguru

kangguru commented May 6, 2015

Copy link
Copy Markdown

i like @DonSchado idea, we might even go further and get rid of posistion and just have

prepend: "<this is my tag>"

or

append: "<this is the tag>"

also there are already some issues with the naive regex approach, we should not drive further into this direction and opening new potential problems

@DonSchado

Copy link
Copy Markdown
Collaborator

salim pls also consider to address this issue here: #28

gsub is bad! ;)

@salimhb

salimhb commented May 6, 2015

Copy link
Copy Markdown
Member Author

#28 can be resolved if we first render the handlers for a certain position together, then inject them in one step.
Any suggestions other than gsub? we could use Nokogiri, but that messes a lot with the response.

@salimhb salimhb changed the title add :container_position option to allow injecting handlers after the opening of the :container_tag Enhance position option with :append and :prepend options to inject code at start or end of head or body tags May 7, 2015
@DonSchado

Copy link
Copy Markdown
Collaborator

in which state is this now? do you need any help on this? or feedback on a specific problem?

@salimhb

salimhb commented May 22, 2015

Copy link
Copy Markdown
Member Author

This is done with the following format now:

self.position body: :append

or

self.position body: :prepend

Of course, it has to be updated with the latest master.

@DonSchado

Copy link
Copy Markdown
Collaborator

first of all, I'm cool with the use case, but to be honest I'm not fully satisfied with this solution.
let's grab some coffee and talk about it later? :)

@salimhb

salimhb commented Jun 11, 2015

Copy link
Copy Markdown
Member Author

let's do that 💚

@DonSchado

Copy link
Copy Markdown
Collaborator

😴

;)

@DonSchado DonSchado closed this Oct 12, 2015
@DonSchado
DonSchado deleted the exact_position branch November 10, 2015 15:43
@DonSchado
DonSchado restored the exact_position branch November 12, 2015 10:20
@jhilden

jhilden commented Nov 12, 2015

Copy link
Copy Markdown
Contributor

I would like to fix this up, so it can be merged.

What exactly would need to be done differently?

Are we OK with the positioning syntax? self.position body: :prepend
(or maybe self.position body: :top?)

@jhilden jhilden reopened this Nov 12, 2015
@bumi

bumi commented Jun 9, 2017

Copy link
Copy Markdown
Contributor

closing this PR in favor of #84

That PR allows handers to define a inject method and manipulate the response directly which gives the handlers quite some flexibility. Though it is not possible for the user to do more position configuration for now.
if somebody needs more flexibility please open a new PR based on the latest master.

@bumi bumi closed this Jun 9, 2017
@kangguru
kangguru deleted the exact_position branch June 9, 2017 16:19
@bumi
bumi restored the exact_position branch June 12, 2017 15:35
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.

5 participants