Skip to content

Commit

Permalink
Refactor "unconfirm" functionality into a gem.
Browse files Browse the repository at this point in the history
- Rename maybe_confirm => unconfirm.
- Add ApplicationHelper to handle session updates.
- Add view helper and accompanying specs.
- Refactor confirmation javascript into a jQuery plugin.
- Add a view helper to generate the unconfirm settings
  and call to the new jQuery plugin.
- Add view and asset pipeline initializer.
- Fix JS bugs and other bugs.
  • Loading branch information
navilan committed Jun 23, 2014
0 parents commit 7cc1ed8
Show file tree
Hide file tree
Showing 68 changed files with 1,741 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
.bundle/
log/*.log
pkg/
spec/dummy/db/*.sqlite3
spec/dummy/log/*.log
spec/dummy/tmp/
spec/dummy/.sass-cache
**/.tern-port

This comment has been minimized.

Copy link
@Dantemss

Dantemss Jun 30, 2014

Member

Might wanna add Gemfile.lock here

This comment has been minimized.

Copy link
@navilan

navilan Jun 30, 2014

Author Contributor

oh... I thought we were checking them in (I saw those in a few of our repos).

This comment has been minimized.

Copy link
@Dantemss

Dantemss Jun 30, 2014

Member

Apps should check in Gemfile.lock, but gems should not, in general.

This comment has been minimized.

Copy link
@navilan

navilan Jul 3, 2014

Author Contributor

I see. Makes sense. Will fix.

17 changes: 17 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Contributing

1. Fork it ( https://github.com/[my-github-username]/unconfirm/fork )
2. Create your feature/bug/refactor branch.
- If its a bug-fix, create bug branch: bug/<issue-number> or bug/<issue-short-description>
- If its a new feature, create a feature branch: feature/<feature-short-description>
- If its code refactoring with no changes to behavior: refactor/<refactoring-short-goals>
(`git checkout -b <feature/bug/refacator>/my-branch` - we'll use `feature/my-feature` as
an example in the rest of this section.)
3. Ensure that there are tests to assert that your changes are working as expected.
3. Commit your changes (`git commit -a`).
4. Push to the branch (`git push -u origin feature/my-feature`).
5. Create a new Pull Request.

[git-extras][] helps with the above workflow.

[git-extras]: https://github.com/visionmedia/git-extras
17 changes: 17 additions & 0 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
source "https://rubygems.org"

# Declare your gem's dependencies in unconfirm.gemspec.
# Bundler will treat runtime dependencies like base dependencies, and
# development dependencies will be added by default to the :development group.
gemspec

# jquery-rails is used by the dummy application
gem "jquery-rails"

# Declare any dependencies that are still in development here instead of in
# your gemspec. These might include edge Rails or gems from your path or
# Git. Remember to move these dependencies to your gemspec before releasing
# your gem to rubygems.org.

# To use debugger
# gem 'debugger'
135 changes: 135 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
PATH
remote: .
specs:
unconfirm (0.0.1)
activerecord-typedstore
jquery-rails
rails (~> 3.2.17)

GEM
remote: https://rubygems.org/
specs:
actionmailer (3.2.18)
actionpack (= 3.2.18)
mail (~> 2.5.4)
actionpack (3.2.18)
activemodel (= 3.2.18)
activesupport (= 3.2.18)
builder (~> 3.0.0)
erubis (~> 2.7.0)
journey (~> 1.0.4)
rack (~> 1.4.5)
rack-cache (~> 1.2)
rack-test (~> 0.6.1)
sprockets (~> 2.2.1)
activemodel (3.2.18)
activesupport (= 3.2.18)
builder (~> 3.0.0)
activerecord (3.2.18)
activemodel (= 3.2.18)
activesupport (= 3.2.18)
arel (~> 3.0.2)
tzinfo (~> 0.3.29)
activerecord-typedstore (0.4.3)
activerecord (>= 3.2)
activeresource (3.2.18)
activemodel (= 3.2.18)
activesupport (= 3.2.18)
activesupport (3.2.18)
i18n (~> 0.6, >= 0.6.4)
multi_json (~> 1.0)
arel (3.0.3)
builder (3.0.4)
capybara (2.3.0)
mime-types (>= 1.16)
nokogiri (>= 1.3.3)
rack (>= 1.0.0)
rack-test (>= 0.5.4)
xpath (~> 2.0)
database_cleaner (1.3.0)
diff-lcs (1.2.5)
erubis (2.7.0)
hike (1.2.3)
i18n (0.6.9)
journey (1.0.4)
jquery-rails (3.1.0)
railties (>= 3.0, < 5.0)
thor (>= 0.14, < 2.0)
json (1.8.1)
mail (2.5.4)
mime-types (~> 1.16)
treetop (~> 1.4.8)
mime-types (1.25.1)
mini_portile (0.6.0)
multi_json (1.10.1)
nokogiri (1.6.2.1)
mini_portile (= 0.6.0)
polyglot (0.3.5)
rack (1.4.5)
rack-cache (1.2)
rack (>= 0.4)
rack-ssl (1.3.4)
rack
rack-test (0.6.2)
rack (>= 1.0)
rails (3.2.18)
actionmailer (= 3.2.18)
actionpack (= 3.2.18)
activerecord (= 3.2.18)
activeresource (= 3.2.18)
activesupport (= 3.2.18)
bundler (~> 1.0)
railties (= 3.2.18)
railties (3.2.18)
actionpack (= 3.2.18)
activesupport (= 3.2.18)
rack-ssl (~> 1.3.2)
rake (>= 0.8.7)
rdoc (~> 3.4)
thor (>= 0.14.6, < 2.0)
rake (10.3.2)
rdoc (3.12.2)
json (~> 1.4)
rspec-core (3.0.1)
rspec-support (~> 3.0.0)
rspec-expectations (3.0.1)
diff-lcs (>= 1.2.0, < 2.0)
rspec-support (~> 3.0.0)
rspec-mocks (3.0.1)
rspec-support (~> 3.0.0)
rspec-rails (3.0.1)
actionpack (>= 3.0)
activesupport (>= 3.0)
railties (>= 3.0)
rspec-core (~> 3.0.0)
rspec-expectations (~> 3.0.0)
rspec-mocks (~> 3.0.0)
rspec-support (~> 3.0.0)
rspec-support (3.0.0)
sprockets (2.2.2)
hike (~> 1.2)
multi_json (~> 1.0)
rack (~> 1.0)
tilt (~> 1.1, != 1.3.0)
sqlite3 (1.3.9)
thor (0.19.1)
tilt (1.4.1)
treetop (1.4.15)
polyglot
polyglot (>= 0.3.1)
tzinfo (0.3.39)
xpath (2.0.0)
nokogiri (~> 1.3)

PLATFORMS
ruby

DEPENDENCIES
bundler (~> 1.6)
capybara
database_cleaner
jquery-rails
rake
rspec-rails
sqlite3
unconfirm!

This comment has been minimized.

Copy link
@Dantemss

Dantemss Jun 30, 2014

Member

And remove this from Github

20 changes: 20 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Copyright 2014 Rice University.

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
71 changes: 71 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
# Unconfirm

This gem helps in creating user-confirmable UI actions with a
persistent "Don't show this message again." facility.

## Installation

Add this line to your application's Gemfile:

gem 'unconfirm'

And then execute:

$ bundle

Or install it yourself as:

$ gem install unconfirm

## Usage

1. DB Migration:

$ rake unconfirm_engine:install:migrations
$ rake db:migrate

2. Update layout: Edit your `application.html.erb` or equivalent layout
file and add the following:


Just before `body` tag is closed:

<%= include_unconfirm %>
<%= unconfirm_tag %>

3. Include unconfirm javascript assets. Add the following to your application
assets (`application.js`):

//= require unconfirm

4. Add configuration file(s) for unconfirm settings:

Under `<RAILS ROOT>/config/unconfirm` add `<category>_setting.yml` file
with any needed settings. See [example user settings file][example] for
format and documentation.
[example]: config/unconfirm/example_user_settings.yml


5. Enable unconfirm.


Change something like the following:

<%= f.submit "Submit",
:name => "save",
:class => 'link_button',
:confirm => "Are you sure?" %>

to:

<%= f.submit "Submit",
:name => "save",
:class => 'link_button unconfirm',
:data => data_with_unconfirm('skip_save_message') %>

6. Test to make sure everything works as expected.

## Contributing

See [contribution guidelines](CONTRIBUTING.md).

35 changes: 35 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
#!/usr/bin/env rake
begin
require 'bundler/setup'
rescue LoadError
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
end
begin
require 'rdoc/task'
rescue LoadError
require 'rdoc/rdoc'
require 'rake/rdoctask'
RDoc::Task = Rake::RDocTask
end

This comment has been minimized.

Copy link
@Dantemss

Dantemss Jun 30, 2014

Member

I usually remove the rdoc task, since we don't use rdoc.


RDoc::Task.new(:rdoc) do |rdoc|
rdoc.rdoc_dir = 'rdoc'
rdoc.title = 'Unconfirm'
rdoc.options << '--line-numbers'
rdoc.rdoc_files.include('README.rdoc')
rdoc.rdoc_files.include('lib/**/*.rb')
end

This comment has been minimized.

Copy link
@Dantemss

Dantemss Jun 30, 2014

Member

Same as above.

This comment has been minimized.

Copy link
@navilan

navilan Jun 30, 2014

Author Contributor

Will do.


APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
load 'rails/tasks/engine.rake'



Bundler::GemHelper.install_tasks

require 'rspec/core'
require 'rspec/core/rake_task'
desc "Run all specs in spec directory (excluding plugin specs)"
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')

task :default => :spec
Empty file.
1 change: 1 addition & 0 deletions app/assets/javascripts/unconfirm.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
//= require_tree .
Loading

0 comments on commit 7cc1ed8

Please sign in to comment.