[Rails-core] feature: Line break retention in simple_format

2013-08-13 Thread Pawel Janiak
There are quite a lot of line break issues with Rails on StackOverflow and 
the web in general. A lot of solutions are ugly and a lot modify 
simple_format so I've created a patch that I'd like to hear thoughts on 
before submitting a PR.

I've made a slight modification to split_paragraphs and how it gsubs the 
newline characters in paragraphs up so that if you pass it a line option, 
instead of getting rid of all newlines and return carriage characters, it 
can substitute \r\n for an html break element.

This way if a saved chunk of text is the following then it won't be 
stripped down to just the 2 lines of text but will have the  tags 
that were obviously intended:

"\r\n\r\n\r\n\r\n\r\n\r\n\r\n\
r\nBig gap.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nPlease."

This doesn't affect the regular behaviour of simple_format and will still 
return the usual result without the option.

I find that this isn't an edge case but is frequent enough to warrant this 
and not have people overriding simple_format and split_paragraphs in their 
application helper.

Thoughts?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.




[Rails-core] simple_format option for intentionally long line breaks

2013-08-13 Thread Pawel Janiak
There are quite a lot of line break issues with Rails on StackOverflow and 
the web in general. A lot of solutions are ugly and a lot modify 
simple_format so I've created a patch that I'd like to hear thoughts on 
before submitting a PR.

I've made a slight modification to split_paragraphs and how it gsubs the 
newline characters in paragraphs up so that if you pass it a line option, 
instead of getting rid of all newlines and return carriage characters, it 
can substitute \r\n for an html break element.

This way if a saved chunk of text is the following then it won't be 
stripped down to just the 2 lines of text but will have the  tags 
that were obviously intended:

"\r\n\r\n\r\n\r\n\r\n\r\n\r\n\
r\nBig gap.\r\n\r\n\r\n\r\n\r\n\r\n\r\n\r\nPlease."

This doesn't affect the regular behaviour of simple_format and will still 
return the usual result without the option.

I find that this isn't an edge case but is frequent enough to warrant this 
and not have people overriding simple_format and split_paragraphs in their 
application helper.

Thoughts?

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.




Re: [Rails-core] Creating Proxy-containers with ActiveSupport's delegate, proposing return_value_of keyword argument

2013-08-13 Thread Matt Jones

On Aug 12, 2013, at 7:25 PM, Amiel Martin wrote:

> I like this idea and I would use it.
> 
> My only suggestion would be to normally return a new instance of the proxy 
> object. This makes it easier to use this feature with immutable objects.
> I know it would be possible to do this:
> 
> class ProxyContainer < Struct.new(:brands)
>   delegate :select, to: :brands, return_value_of: 'self.class.new(result)'
>   # ...
> end
> 
> but it's not obvious that you could do this without reading through the 
> definition.

We already have a DSL for specifying the return value of a method: it's called 
RUBY. :)

Snark aside, I think adding too many bells-and-whistles to `delegate` is not 
the best idea. If you really want custom behavior, why not make it clearer and 
just write the methods?

At a minimum, code-as-string is kinda gross. 

--Matt Jones




-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to rubyonrails-core+unsubscr...@googlegroups.com.
To post to this group, send email to rubyonrails-core@googlegroups.com.
Visit this group at http://groups.google.com/group/rubyonrails-core.
For more options, visit https://groups.google.com/groups/opt_out.