editable_areas 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +21 -0
- data/.rspec +1 -0
- data/.travis.yml +3 -0
- data/CHANGELOG.md +3 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +77 -0
- data/Rakefile +23 -0
- data/app/controllers/editable_areas_controller.rb +24 -0
- data/app/helpers/editable_areas_helper.rb +21 -0
- data/app/models/editable_area.rb +3 -0
- data/app/views/editable_areas/_editable_area.html.erb +1 -0
- data/app/views/editable_areas/_form.html.erb +20 -0
- data/config/routes.rb +3 -0
- data/editable_areas.gemspec +29 -0
- data/lib/editable_areas.rb +4 -0
- data/lib/editable_areas/editable_area_additions.rb +11 -0
- data/lib/editable_areas/engine.rb +9 -0
- data/lib/editable_areas/version.rb +3 -0
- data/lib/generators/editable_areas_generator.rb +15 -0
- data/lib/generators/templates/create_editable_areas.rb +12 -0
- data/spec/controllers/areas_controller_spec.rb +55 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/javascripts/application.js +13 -0
- data/spec/dummy/app/assets/stylesheets/application.css +13 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/views/layouts/application.html.erb +14 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +4 -0
- data/spec/dummy/bin/rake +4 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +5 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +29 -0
- data/spec/dummy/config/environments/production.rb +80 -0
- data/spec/dummy/config/environments/test.rb +36 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +5 -0
- data/spec/dummy/config/initializers/secret_token.rb +12 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +3 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +58 -0
- data/spec/dummy/public/422.html +58 -0
- data/spec/dummy/public/500.html +57 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/extra/schema.rb +10 -0
- data/spec/helpers/areas_helper_spec.rb +57 -0
- data/spec/models/area_spec.rb +24 -0
- data/spec/routing/areas_routing_spec.rb +9 -0
- data/spec/spec_helper.rb +25 -0
- metadata +239 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 0586b45e191c4d27b12c82df899a4f84219505b0
|
4
|
+
data.tar.gz: aa19867980c9d2deda1a4babfc9f1f44e64f5fef
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 7f6705a0c81ddcd8eb0f6674b35ab56f80acd1e7f55f8fdad0fb228bc3b8bb455436dee96afea9a2602e943e617bde10325b2c1fc694dba3ff7a1ea8f4e565e0
|
7
|
+
data.tar.gz: cc32bebef5a017cc185eeaafdb679bc1f65e39cd3527f25e9e745aa4b54dc97d6e77b93672598a26bcd0b147d6aa3567e4f09591c853cf97505e58e786622e10
|
data/.gitignore
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
spec/dummy/log/*.log
|
18
|
+
tmp
|
19
|
+
.project
|
20
|
+
spec/log/*.log
|
21
|
+
/nbproject
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/CHANGELOG.md
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Kainage
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
# Editable Areas
|
2
|
+
|
3
|
+
[![Build Status](https://travis-ci.org/kainage/editable_areas.png)](https://travis-ci.org/kainage/editable_areas)
|
4
|
+
|
5
|
+
Requires ruby >= **v2.0**
|
6
|
+
Requires rails >= **v4.0.0.rc1**
|
7
|
+
|
8
|
+
Renders text or an editor anywhere in your rails 4 application
|
9
|
+
|
10
|
+
## Installation
|
11
|
+
|
12
|
+
Add this line to your application's Gemfile:
|
13
|
+
|
14
|
+
gem 'editable_areas'
|
15
|
+
|
16
|
+
And then execute:
|
17
|
+
|
18
|
+
$ bundle
|
19
|
+
|
20
|
+
Or install it yourself as:
|
21
|
+
|
22
|
+
$ gem install editable_areas
|
23
|
+
|
24
|
+
Run the generator:
|
25
|
+
|
26
|
+
$ rails g editable_areas
|
27
|
+
|
28
|
+
This will create the migration file.
|
29
|
+
|
30
|
+
Migrate the database:
|
31
|
+
|
32
|
+
$ rake db:migrate
|
33
|
+
|
34
|
+
## Usage
|
35
|
+
|
36
|
+
Add one of the helper methods to one of your pages:
|
37
|
+
|
38
|
+
```
|
39
|
+
<%= render_or_edit_area_with_button(title: 'Title' accessible: true) %>
|
40
|
+
```
|
41
|
+
The accessible option will hide the edit button and never render the editable form
|
42
|
+
(will always render the content) if false. Pass in an _admin_ or _moderator_ etc.
|
43
|
+
check here.
|
44
|
+
|
45
|
+
You will now have a blank div with the class "editable_area" and an edit button.
|
46
|
+
Clicking on the edit button will return you to the same page, but there will be a
|
47
|
+
textarea for you to edit.
|
48
|
+
|
49
|
+
Submitting the form will return you to the same page with the content loaded and
|
50
|
+
the edit button back in place (if accessible)
|
51
|
+
|
52
|
+
Note that even if an unauthorized user appends _?edit=true_ to the url, it will
|
53
|
+
not render the form unless ```accessible = true```
|
54
|
+
|
55
|
+
If you want to render the form/content and the button separately you can:
|
56
|
+
|
57
|
+
```
|
58
|
+
<%= render_or_edit_area(title: 'Title', accessible: true) %> # Renders only the content or form
|
59
|
+
|
60
|
+
<%= render_edit_area_button(accessible: true) %> # Renders only the edit button
|
61
|
+
```
|
62
|
+
|
63
|
+
By default the textarea has a class of "ckeditor" if you want to hook into that
|
64
|
+
or you use the _ckeditor-rails_ gem. If not, you can just ignore this.
|
65
|
+
|
66
|
+
### CanCan integration
|
67
|
+
|
68
|
+
If you are using CanCan for authorization, the ```EditableAreasController``` will
|
69
|
+
automatically add authorization to the _update_ action with ```authorize! :update, @editable_area```.
|
70
|
+
|
71
|
+
## Contributing
|
72
|
+
|
73
|
+
1. Fork it
|
74
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
75
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
76
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
77
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
begin
|
3
|
+
require 'bundler/setup'
|
4
|
+
rescue LoadError
|
5
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
6
|
+
end
|
7
|
+
|
8
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
9
|
+
|
10
|
+
load 'rails/tasks/engine.rake'
|
11
|
+
|
12
|
+
Bundler::GemHelper.install_tasks
|
13
|
+
|
14
|
+
Dir[File.join(File.dirname(__FILE__), 'tasks/**/*.rake')].each {|f| load f }
|
15
|
+
|
16
|
+
require 'rspec/core'
|
17
|
+
require 'rspec/core/rake_task'
|
18
|
+
|
19
|
+
desc "Run all specs in spec directory (excluding plugin specs)"
|
20
|
+
|
21
|
+
RSpec::Core::RakeTask.new(:spec => 'app:db:test:prepare')
|
22
|
+
|
23
|
+
task :default => :spec
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class EditableAreasController < ApplicationController
|
2
|
+
# PATCH/PUT /editable_area/1
|
3
|
+
# PATCH/PUT /editable_area/1.json
|
4
|
+
def update
|
5
|
+
@editable_area = EditableArea.find(params[:id])
|
6
|
+
authorize! :update, @editable_area if defined? CanCan::Ability
|
7
|
+
|
8
|
+
respond_to do |format|
|
9
|
+
if @editable_area.update_attributes(editable_area_params)
|
10
|
+
format.html { redirect_to request.referrer.split('?').first, notice: 'Editable area was successfully updated.' }
|
11
|
+
format.json { head :no_content }
|
12
|
+
else
|
13
|
+
format.html { redirect_to request.referrer, notice: @editable_area.errors.full_messages.join(', ') }
|
14
|
+
format.json { render json: @editable_area.errors, status: :unprocessable_entity }
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
private
|
20
|
+
|
21
|
+
def editable_area_params
|
22
|
+
params.require(:editable_area).permit(:content)
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module EditableAreasHelper
|
2
|
+
def render_or_edit_area(title, accessible: true)
|
3
|
+
editable_area = EditableArea.place(title)
|
4
|
+
|
5
|
+
if params[:edit] && accessible
|
6
|
+
render 'editable_areas/form', :editable_area => editable_area
|
7
|
+
else
|
8
|
+
render editable_area
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
def render_edit_area_button(accessible: true)
|
13
|
+
link_to 'Edit', request.fullpath + '?edit=true', :class => 'editable_area_btn' if params[:edit].blank? && accessible
|
14
|
+
end
|
15
|
+
|
16
|
+
def render_or_edit_area_with_button(title, accessible: true)
|
17
|
+
content_tag :div, :class => 'editable_area' do
|
18
|
+
render_or_edit_area(title, accessible: accessible) + render_edit_area_button(accessible: accessible)
|
19
|
+
end.html_safe
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1 @@
|
|
1
|
+
<%= raw editable_area.content %>
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%= form_for(editable_area) do |f| %>
|
2
|
+
<% if editable_area.errors.any? %>
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2><%= pluralize(area.errors.count, "error") %> prohibited this editable area from being saved:</h2>
|
5
|
+
|
6
|
+
<ul>
|
7
|
+
<% editable_area.errors.full_messages.each do |msg| %>
|
8
|
+
<li><%= msg %></li>
|
9
|
+
<% end %>
|
10
|
+
</ul>
|
11
|
+
</div>
|
12
|
+
<% end %>
|
13
|
+
|
14
|
+
<div class="field">
|
15
|
+
<%= f.text_area :content, :class => 'ckeditor' %>
|
16
|
+
</div>
|
17
|
+
<div class="actions">
|
18
|
+
<%= f.submit %>
|
19
|
+
</div>
|
20
|
+
<% end %>
|
data/config/routes.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'editable_areas/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "editable_areas"
|
8
|
+
spec.version = EditableAreas::VERSION
|
9
|
+
spec.authors = ["Kainage"]
|
10
|
+
spec.email = ["kainage@gmail.com"]
|
11
|
+
spec.description = %q{Renders text or an editor anywhere in your rails 4 application}
|
12
|
+
spec.summary = %q{Renders text or an editor anywhere in your rails 4 application}
|
13
|
+
spec.homepage = "https://github.com/kainage/editable_area"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "rails", "~> 4.0.0.rc1"
|
22
|
+
|
23
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
24
|
+
spec.add_development_dependency "rake"
|
25
|
+
spec.add_development_dependency "rspec"
|
26
|
+
spec.add_development_dependency "sqlite3"
|
27
|
+
spec.add_development_dependency "shoulda-matchers"
|
28
|
+
spec.add_development_dependency "rspec-rails"
|
29
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require 'rails/generators/migration'
|
2
|
+
|
3
|
+
class EditableAreasGenerator < Rails::Generators::Base
|
4
|
+
include Rails::Generators::Migration
|
5
|
+
|
6
|
+
source_root File.expand_path("../templates", __FILE__)
|
7
|
+
|
8
|
+
def self.next_migration_number(path)
|
9
|
+
Time.now.utc.strftime("%Y%m%d%H%M%S")
|
10
|
+
end
|
11
|
+
|
12
|
+
def create_editable_areas_files
|
13
|
+
migration_template "create_editable_areas.rb", "db/migrate/create_editable_areas.rb"
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,55 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EditableAreasController do
|
4
|
+
before :each do
|
5
|
+
request.env["HTTP_REFERER"] = "http://localhost:3000"
|
6
|
+
end
|
7
|
+
|
8
|
+
def valid_attributes
|
9
|
+
{ "title" => "MyString" }
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "PUT update" do
|
13
|
+
describe "with valid params" do
|
14
|
+
it "updates the requested editable_area" do
|
15
|
+
editable_area = EditableArea.create! valid_attributes
|
16
|
+
# Assuming there are no other editable_areas in the database, this
|
17
|
+
# specifies that the Area created on the previous line
|
18
|
+
# receives the :update_attributes message with whatever params are
|
19
|
+
# submitted in the request.
|
20
|
+
EditableArea.any_instance.should_receive(:update_attributes).with({ "content" => "MyString" })
|
21
|
+
put :update, {:id => editable_area.to_param, :editable_area => { "content" => "MyString" }}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "assigns the requested editable_area as @editable_area" do
|
25
|
+
editable_area = EditableArea.create! valid_attributes
|
26
|
+
put :update, {:id => editable_area.to_param, :editable_area => valid_attributes}
|
27
|
+
assigns(:editable_area).should eq(editable_area)
|
28
|
+
end
|
29
|
+
|
30
|
+
it "redirects to the editable_area" do
|
31
|
+
editable_area = EditableArea.create! valid_attributes
|
32
|
+
put :update, {:id => editable_area.to_param, :editable_area => valid_attributes}
|
33
|
+
response.should redirect_to(request.referrer)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
|
37
|
+
describe "with invalid params" do
|
38
|
+
it "assigns the editable_area as @editable_area" do
|
39
|
+
editable_area = EditableArea.create! valid_attributes
|
40
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
41
|
+
EditableArea.any_instance.stub(:save).and_return(false)
|
42
|
+
put :update, {:id => editable_area.to_param, :editable_area => { "title" => "invalid value" }}
|
43
|
+
assigns(:editable_area).should eq(editable_area)
|
44
|
+
end
|
45
|
+
|
46
|
+
it "re-renders the 'edit' template" do
|
47
|
+
editable_area = EditableArea.create! valid_attributes
|
48
|
+
# Trigger the behavior that occurs when invalid params are submitted
|
49
|
+
EditableArea.any_instance.stub(:save).and_return(false)
|
50
|
+
put :update, {:id => editable_area.to_param, :editable_area => { "title" => "invalid value" }}
|
51
|
+
response.should redirect_to(request.referrer)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
== README
|
2
|
+
|
3
|
+
This README would normally document whatever steps are necessary to get the
|
4
|
+
application up and running.
|
5
|
+
|
6
|
+
Things you may want to cover:
|
7
|
+
|
8
|
+
* Ruby version
|
9
|
+
|
10
|
+
* System dependencies
|
11
|
+
|
12
|
+
* Configuration
|
13
|
+
|
14
|
+
* Database creation
|
15
|
+
|
16
|
+
* Database initialization
|
17
|
+
|
18
|
+
* How to run the test suite
|
19
|
+
|
20
|
+
* Services (job queues, cache servers, search engines, etc.)
|
21
|
+
|
22
|
+
* Deployment instructions
|
23
|
+
|
24
|
+
* ...
|
25
|
+
|
26
|
+
|
27
|
+
Please feel free to use a different markup language if you do not plan to run
|
28
|
+
<tt>rake doc:app</tt>.
|