[ANN] New plugin - Personalise Site

This plugin provides helpers for your views that allow you to gain
implicit data about the user browsing the site.

This is intended to be used to customise what the user see’s, maybe to
improve usability or for cross-browser issues

Url: http://www.railslodge.com/plugins/303-personalise-site
SVN: http://svn.railslodge.com/svn/plugins/personalise_site/

The following methods are available:

Returns the name of the browser the user is using
<%= def which_browser? %>

Returns the version number of the browser being used
<%=which_browser_version?%>

Returns the name of the platform the user is using
<%= which_platform? %>

Nil is always returned if the data is unavailable

==== Example usage

An example below looks at the platform and outputs the right command to
install this plugin

<% if which_platform? == ‘Windows’ -%>
ruby script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% elsif which_platform? == ‘Mac’ -%>
./script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% else -%>
script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% end -%>

Info

Author: Scott S.
License: MIT
Date: 30-09-07

This is a stylistic nit pick, but typically methods that end in “?”
return true or false rather than some other value. I would personally
name the methods “user_browser_version” or “user_platform” or
something like that.

–Jeremy

On 9/30/07, Scott A S [email protected] wrote:

The following methods are available:
Nil is always returned if the data is unavailable
./script/plugin install
Date: 30-09-07

Posted via http://www.ruby-forum.com/.


http://www.jeremymcanally.com/

My free Ruby e-book:
http://www.humblelittlerubybook.com/book/

My blogs:
http://www.mrneighborly.com/
http://www.rubyinpractice.com/

Hi Jeremy,

Thanks for your feedback,
I have made the changes to remove the ‘?’ based on your comments.

Cheers,
Scott S.

Jeremy McAnally wrote:

This is a stylistic nit pick, but typically methods that end in “?”
return true or false rather than some other value. I would personally
name the methods “user_browser_version” or “user_platform” or
something like that.

–Jeremy

Just some ideas…

On 10/1/07, Scott A S [email protected] wrote:

Hi Jeremy,

Thanks for your feedback,
I have made the changes to remove the ‘?’ based on your comments.

You could also add some methods like the following:

running_windows?
running_os_x?

then your example becomes:

<% if running_windows? -%>
ruby script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% elsif running_os_x? -%>
./script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% else -%>
script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% end -%>

Cheers,

Scott A S wrote:

Yeah it’s a good idea, however this would require an extra 5 or 6
methods to replace the single which_platform.

As I am very likley to be devleoping this one further, I really want to
keep the code as small and DRY as possible.

I dig it. If you really want methods like internet_explorer? you could
easily write your own. I probably will. =)

Thanks for the plugin, Scott.

  • Rabbit

Hi,

Yeah it’s a good idea, however this would require an extra 5 or 6
methods to replace the single which_platform.

As I am very likley to be devleoping this one further, I really want to
keep the code as small and DRY as possible.

Scott

Michael G. wrote:

You could also add some methods like the following:

running_windows?
running_os_x?

then your example becomes:

<% if running_windows? -%>
ruby script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% elsif running_os_x? -%>
./script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% else -%>
script/plugin install
http://svn.railslodge.com/svn/plugins/personalise_site/
<% end -%>

Cheers,

What? Replace methods? No way. Just add some nice convenience methods to
pretty up the views.

For example:

def running_osx?
which_platform == ‘Mac’
end

def running_windows
which_platform == “Windows”
end

Etc. You’re not replacing methods… you are adding a DSL to your
plugin…
which makes views much easier.

It also allows you to change the underlying implementation. For
example…
which_platform might return “Windows” right now… but what if it
returns
win32 in some cases? It might also return something else in the future.

This is one reason why you access your params in a Rails application via
params (a method) and not @params (an instance variable)

Nice plugin btw… have you submitted this to
agilewebdevelopment.com/plugins yet?

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs