Coder Social home page Coder Social logo

thetron / css3buttons_rails_helpers Goto Github PK

View Code? Open in Web Editor NEW
315.0 8.0 29.0 102 KB

Rails helpers to generate beautiful css3 buttons, based on the 'css3-github-buttons'

Home Page: http://nicolasgallagher.com/lab/css3-github-buttons/

License: MIT License

Ruby 100.00%

css3buttons_rails_helpers's Introduction

css3buttons

The css3buttons gem is a small set of helper methods designed to work in conjunction with the amazing css3 github buttons by Nicolas Gallagher.

The helpers allow rails developers to quickly and easily leverage this fantastic CSS library - without cluttering up your views and calls to link_to, button_to and submit_tag.

Version 1.0 is finally here!

And with it brings support for the Rails 3.1 asset pipeline. Please note: as of version 1.0.0, Rails 3.0.x is no longer supported. If you're wanting to use the css3buttons on a Rails 3.0.x project, please install version 0.9.5 (see below for full instructions).

Getting started - Rails 3.1

Include the gem in your gemfile and run bundle install

gem 'css3buttons'

Require the stylesheets in app/assets/stylesheets/application.css:

*= require css3buttons
*= require_self
...

By default, css3buttons comes with a reset stylesheet built in. Because of this, you should load it before any other stylesheets. However, if you don't want to use reset, or already have your own, just require this instead:

*= require css3buttons/without-reset
*= require_self
...

Getting started - Rails 3.0.x

Include the gem in your gemfile and run 'bundle install`

gem 'css3buttons', '0.9.5'

Run the generators:

$ rails g css3buttons

Which will copy the stylesheets and icon/button images into your public directory.

In your layout, add the following:

<%= css3buttons_stylesheets %>

Which will add both the reset.css and the css3buttons.css stylesheet link tags.

By default, css3buttons comes with a reset stylesheet built in. Because of this, you should load it before any other stylesheets. However, if you'd like to use your own reset, you can skip it with:

<%= css3buttons_stylesheets :include_reset => false %>

The basics

To change your link_to calls to buttons, simply use button_link_to. For example:

<%= button_link_to "Search", search_path %>

The helper methods accept all the same parameters as link_to so upgrading and downgrading to css3buttons should be a snap.

Icons and pills and colours, oh my!

The gem also responds to a huge list of dynamic helper methods, to assist in adding icons, colours and styles to your buttons. Unlike previous versions of the gem, you can now add any of the features in any order.

Icons

To add an icon from the current icon list, simply prepend the helper method with the name of the icon you'd like to use. For example:

<%= magnifier_button_link_to "Search", search_path %>
<%= user_button_link_to "Account", edit_current_user_path %>
<%= pin_button_link_to "Mark on map", edit_map_path %>

Styles

Just like the icons, you can add options for primary, big and pill.

<%= primary_button_link_to "Home", root_path %>
<%= pill_button_link_to "Archive", archive_path %>
<%= big_primary_pill_button_link_to "Super Important!", super_important_path %>

Colors

Again with colors - simply add positive or negative to the front of your method call:

<%= negative_trash_button_link_to "Delete", delete_path %>
<%= positive_pill_reload_button_link_to "Reload", reload_path %>

In order to be compatible with the new css3 github buttons library, you can also use danger and safe - as alternatives.

Button groups

Button groups are snap, you just need to wrap your buttons with button_group, like so:

<%= button_group do %>
  <%= button_link_to "Show", @post %>
  <%= button_link_to "Edit", edit_post_path(@post) %>
  <%= negative_trash_button_link_to "Delete", @post, :confirm => "Are you sure? %>
<% end %>

And, of course, minor groups:

<%= minor_button_group do %>
  You know the drill by now.
<% end %>

Submit tags, button tags and using icons on form buttons

Submit tags were ushered in with version 0.9.2. Everything works as it does above, except instead of button_link_to it's button_submit_tag. Example:

<%= positive_button_submit_tag "Publish" %>

Keep in mind however, that icons do not work on <submit> tags. If you're wanting to include icons in your forms there is also a helper method to insert <button> tags instead. The method suffix in this case is button_tag. Examples:

<%= approve_button_tag "Update profile" %>
<%= negative_trash_button_tag "Deactivate account" %>

Formtastic compatibility

If you're using formtastic, you may experience issues with using css3buttons in your forms, due to the way the built-in formtastic styles modify default form buttons. In this instance, you can insert the following into your formtastic_changes.css stylesheet.

form.formtastic input.button, form.formtastic.button.button {
  height: 25px;
  padding: 0.2em 1em 0.2em 2.5em;
  font-family: sans-serif;
  font-size: 11px;
  margin-left: 5px;
}

CSS Snippet courtesy of vitobotta.

What's missing?

The button_group helper needs some proper tests, if anyone can point me as to how to stub out a rails request template in RSpec (or the right way to approach this test at all), that would be much appreciated!

I've noticed that this version of the css3 github buttons does not include any colours for the positive/safe styles - so this will appear as normal buttons, unless you add your own styling.

Forks and pull requests are always welcome.

css3buttons_rails_helpers's People

Contributors

thetron avatar torzech avatar ylansegal avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

css3buttons_rails_helpers's Issues

No icons displayed for button_submit_tag

Hi, first of all thanks a lot for this gem. I like the buttons and the quick and easy integration with Rails.
The only thing is that if I use the button_submit_tag in forms, icons are not displayed like for the button_link_to. Also, the styling is wrong for the button_submit_tag while is correct for the button_link_to.

For the second issue, I am using this CSS so that the submit tag looks like the other buttons:

form.formtastic input.button {
height: 25px;
padding: 0.2em 1em 0.2em 2.5em;
font-family: sans-serif;
font-size: 11px;
margin-left: 5px;
}

As you can see I am using Formtastic so perhaps some attributes need fixing because they were changed by Formtastic's CSS. But I haven't yet managed to get submit_tag buttons displayed with the icon. So for example if in a form I have this:

approve_button_submit_tag "Update project"

The submit button is rendered correctly (thanks to the CSS above) and works correctly, but the "approve" icon is not displayed.
See this picture for example: example

Any idea on how to fix this?

Thanks in advance
Vito

Doesn't seem to work with Rails 3.1.0.rc5

The gem doesn't seem to work with Rails 3.1.0.rc5 - I've just tried it in a brand new application here.

I've followed the documentation, as far as adding:

gem 'css3buttons'

...to my Gemfile, and adding:

*= require css3buttons

...to my app/assets/stylesheets/application.css.

All I get is a Sprockets compilation error, because the file cannot be found. I can see it installed in my system gems, but it would appear that Sprockets isn't looking at those paths.

Any advice for getting this up and running?

link with block is not supported

the examples:
@template.tag_button_link_to '/nothing' do
"abc"
end
=> "<a href="/nothing">abc"
I look into the source code and it seems nothing was done when there is a block.

Generator option required to specify install path

$ rails g css3buttons admin

Should install the stylesheets to and javascripts to:

/stylesheets/admin/
/javascripts/admin/

Should also add a config initializer, which configures the install path:

Cs33buttons.configure do |config|
  config.install_path = "admin"
end

SASS mixins in css3buttons?

This issue is not bug report. It is discuss.

In first, I want to say css3buttons (and css3buttons_rails_helpers too) is awesome project!

Problem: plain CSS-framework has some defects.

  1. Class-name collisions: .button class has too general name and it can conflicts with other css-framework or user styles.
  2. IMHO, class-names chaining is ugly. Take a look at following code (it's haml):
.actions.button-group
  %a.add.button.primary.safe.icon.add(href="blabla") Add
  %a.delete.button.danger.icon.remove(href="blabla") Destroy

Why can't I write semantic class names only?

.actions
  %a.add(href="...") Add
  %a.delete(href="...") Destroy
  1. We can't inject css3buttons in unobtrusive style. Css3buttons_rails_helpers uses some special css-styles for formtastic but what's about simple_form or something another?

Solution: transform css-framework to sass-framework (I did it already, take a look at my fork https://github.com/antage/css3buttons_rails_helpers).

  1. Name collisions: we can import sass-mixins without any css-styles.
  2. Semantic class names: we can include sass-mixins in user-defined styles.
    Example (see html code in example above):
@import "css3buttons/mixins";

.actions {
  @include css3buttons-button-group;

  > a {
    @include css3buttons-button;
    @include css3buttons-button-in-group;
  }
  > a:first-child { @include css3buttons-button-in-begin-of-group;  }
  > a:last-child { @include css3buttons-button-in-end-of-group; }

  a.add {
    @include css3buttons-safe;
    @include css3buttons-primary;
    @include css3buttons-icon-add;
  }

  a.delete {
    @include css3buttons-danger;
    @include css3buttons-icon-remove;
  }
}
  1. Inject css3buttons in formtastic in unobtrusive style:
@import "css3buttons/mixins";

.formtastic {
    .button input {
        @include css3buttons-button;
    }

    .button.commit input {
        @include css3buttons-primary;
    }

    .buttons {
        padding-left: 0;
    }

    .buttons {
        @include css3buttons-button-group;

        .button {
            padding-right: 0;
        }

        .button input {
            @include css3buttons-button-in-group;
        }

        .button:not(:first-child):not(:last-child) input {
            @include css3buttons-button-in-middle-of-group;
        }

        .button:first-child input {
            @include css3buttons-button-in-begin-of-group;
        }

        .button:last-child input {
            @include css3buttons-button-in-end-of-group;
        }
    }
}
  1. BONUS: we can keep backward compatibility - styles.css

What do you think?

Formtastic compatibility

Hi,

I am using css3buttons_rails_helpers with formtastic and I am having some issues. The submit button doesn't look right.

I'm using Rails 3.1

application.css

/*
 * This is a manifest file that'll automatically include all the stylesheets available in this directory
 * and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
 * the top of the compiled file, but it's generally better to create a new file per style scope.
 *= require_self
 *= require_tree . 
 *= require formtastic
 *= require my_formtastic_changes
 *= require css3buttons/without-reset
*/

my_formtastic_changes.css

form.formtastic input.button, form.formtastic.button.button {
  height: 25px;
  padding: 0.2em 1em 0.2em 2.5em;
  font-family: sans-serif;
  font-size: 11px;
  margin-left: 5px;
}

The problematic code:

= semantic_form_for @mentor do |f|
  = f.input :name
  = f.commit_button 'Save new mentor'

This is what I see:

http://dl.dropbox.com/u/834494/screenshot.png

button_submit to form builder

Hi.

A small feature request:

Please add something like button_submit, which looks like "submit (ActionView::Helpers::FormBuilder)". The nice thing with it is that it sets the caption (update/create) depending on whether or not the form updates or creates a new model object.

Incorrect path to icon image

I created a button using add_button_link_to and the button was there but the icon was not showing. Using the web inspector in Chrome I found that it was trying to load the icon image from http://localhost:3000/stylesheets/css3buttons/gh-icons.png yet that file does not exist at that location.

In the CSS I found that it specifies:

background: url(gh-icons.png) 0 99px no-repeat;

I had to modify it to use the correct path and filename.

background: url(/images/css3buttons/css3-github-buttons-icons.png) 0 99px no-repeat;

Sorry I didn't submit a pull request; I'm not very good with Git yet.

[rails g css3buttons] command throwing an error, gem ver. 0.9.5, rails 3.05

Just installed the gem using bundle install. Now trying to run the generator and here is the error output...running 'rails g css3buttons' (help is greatly appreciated!):

/usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/core_ext/file_binary_read.rb:5:in initialize': Permission denied - /usr/local/lib/ruby/gems/1.8/gems/css3buttons-0.9.5/lib/generators/css3buttons/templates/public/images/gh-icons.png (Errno::EACCES) from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/core_ext/file_binary_read.rb:5:inopen'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/core_ext/file_binary_read.rb:5:in binread' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:27:incopy_file'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:in call' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb:54:inrender'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb:47:in identical?' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb:73:inon_conflict_behavior'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/empty_directory.rb:111:in invoke_with_conflict_check' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb:61:ininvoke!'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions.rb:95:in action' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/create_file.rb:26:increate_file'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/actions/file_manipulation.rb:26:in copy_file' from /usr/local/lib/ruby/gems/1.8/gems/css3buttons-0.9.5/lib/generators/css3buttons/css3buttons_generator.rb:6:incopy_stylesheets_and_images'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/task.rb:22:in send' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/task.rb:22:inrun'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/invocation.rb:118:in invoke_task' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/invocation.rb:124:ininvoke_all'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/shell.rb:14:in map' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/core_ext/ordered_hash.rb:73:ineach'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/invocation.rb:124:in map' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/invocation.rb:124:ininvoke_all'
from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/group.rb:226:in dispatch' from /usr/local/lib/ruby/gems/1.8/gems/thor-0.14.6/lib/thor/base.rb:389:instart'
from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/generators.rb:163:in invoke' from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/commands/generate.rb:10 from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:inrequire'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:596:in new_constants_in' from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:225:inload_dependency'
from /usr/local/lib/ruby/gems/1.8/gems/activesupport-3.0.5/lib/active_support/dependencies.rb:239:in require' from /usr/local/lib/ruby/gems/1.8/gems/railties-3.0.5/lib/rails/commands.rb:17 from script/rails:6:inrequire'
from script/rails:6

minor_button_group

<%= minor_button_group => true do %>
....
<% end %>

when i try this i do have an error :
compile error
.../app/views/app/index.html.erb:1: syntax error, unexpected tASSOC, expecting kEND
...append= minor_button_group => true do @output_buffer.safe_c...

Version Bump

Hey, now that Rails 3.1 is out, could you bump your gem so the <%= asset_path %> is used? You've already fixed this but the gem version doesn't have that change.

Thanks!

generate wrong asset url when precompile assets

rails 3.1.0.rc5

in production mode, when i have:

config.action_controller.asset_host = 'http://assets.mydomain.com'

it generates:

url(css3buttons/icons.png)

it should generates:

url(http://assets.mydomain.com/assets/css3buttons/icons-md5hash.png)

negative background not working inside minor_button_group

This doesn't result in red background on :hover for the last link

    <% minor_button_group do -%>
      <%= pill_button_link_to 'Show', project %>
      <%= edit_pill_button_link_to 'Edit', edit_project_path(project) %>
      <%= remove_negative_pill_button_link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %>
   <% end -%>

This does:

    <% button_group do -%>
      <%= pill_button_link_to 'Show', project %>
      <%= edit_pill_button_link_to 'Edit', edit_project_path(project) %>
      <%= remove_negative_pill_button_link_to 'Destroy', project, :confirm => 'Are you sure?', :method => :delete %>
   <% end -%>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.