Skip to content
This repository has been archived by the owner on Nov 17, 2018. It is now read-only.

Documentation fixes + Force default for JS #31

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 16 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,15 +45,17 @@ Gravatar gives you some options. You can use them like this:

That will show R rated Gravatars over a secure connection. If you find yourself using the same options over and over again, you can set the Gravatar defaults. In your model, just change the `is_gravtastic` line to something like this:

gravtastic :secure => true,
:filetype => :gif,
:size => 120
gravtastic :secure => false,
:filetype => :gif,
:size => 120

Now all your Gravatars will come from a secure connection, be a GIF and be 120x120px.

Gravatar needs an email address to find the person's avatar. By default, Gravtastic calls the `#email` method to find this. You can customise this.
Gravatar needs an email address to find the person's avatar. By default, Gravtastic calls the `#email` method to find this. You can explicitly choose it providing the additional first parameter:

gravtastic :author_email
gravtastic :author_email,
:size => 100,
:secure => false

### Defaults

Expand All @@ -68,7 +70,7 @@ The best way to do this is to set the `:default` option when using `#gravatr_url
<th>Option</th>
<th>Description</th>
<th>Default</th>
<th>Values<th>
<th>Values</th>
</tr>
<tr>
<td><b>secure</b></td>
Expand All @@ -86,7 +88,7 @@ The best way to do this is to set the `:default` option when using `#gravatr_url
<td><b>default</b></td>
<td>The default avatar image</td>
<td><i>none</i></td>
<td>"identicon", "monsterid", "wavatar" or an absolute URL.</td>
<td>"404", "mm", "identicon", "monsterid", "wavatar", "retro" or an absolute URL.</td>
</tr>
<tr>
<td><b>rating</b></td>
Expand All @@ -99,9 +101,15 @@ The best way to do this is to set the `:default` option when using `#gravatr_url
<td>The filetype of the image</td>
<td>png</td>
<td>gif, jpg or png</td>
</tr>
<tr>
<td><b>forcedefault</b></td>
<td>Force the default image to always load</td>
<td>false</td>
<td>true/false</td>
</tr> </tr>
</table>

Gravtastic also adds in URL any other options without changing them.

### Other ORMs

Expand Down
21 changes: 17 additions & 4 deletions vendor/assets/javascripts/gravtastic.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,26 @@

# Private abbreviations
abbreviations =
size: 's'
default: 'd'
rating: 'r'
size: 's'
default: 'd'
rating: 'r'
forcedefault: 'f'

window.Gravtastic = (email, options={}) ->
id = MD5(email.toString().toLowerCase())

process_options = (options) ->
processed_options = {}
for key, val of options
switch key
when "secure" then
when "filetype" then
when "forcedefault"
if val
processed_options[key] = 'y'
else processed_options[key] = val
processed_options

# Initialize options
opts = {}
opts[key] = val for key, val of Gravtastic.defaults
Expand All @@ -22,7 +35,7 @@ window.Gravtastic = (email, options={}) ->
path = "/#{id}.#{opts.filetype || 'png'}"

params = "?" + (
for key, val of opts when key isnt "secure" and key isnt "filetype"
for key, val of process_options(opts)
"#{abbreviations[key] || key}=#{val}"
).join('&')

Expand Down