bootsy-rails3 2.0.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +15 -0
- data/MIT-LICENSE +20 -0
- data/README.md +155 -0
- data/Rakefile +38 -0
- data/app/assets/images/bootsy/gallery-loader.gif +0 -0
- data/app/assets/images/bootsy/upload-loader.gif +0 -0
- data/app/assets/javascripts/bootsy.js +8 -0
- data/app/assets/javascripts/bootsy/bootstrap-wysihtml5.js +530 -0
- data/app/assets/javascripts/bootsy/bootstrap.file-input.js +122 -0
- data/app/assets/javascripts/bootsy/bootsy.js +305 -0
- data/app/assets/javascripts/bootsy/editor_options.js +80 -0
- data/app/assets/javascripts/bootsy/init.js +31 -0
- data/app/assets/javascripts/bootsy/locales/bootstrap-wysihtml5.pt-BR.js +50 -0
- data/app/assets/javascripts/bootsy/locales/bootsy.pt-BR.js +9 -0
- data/app/assets/javascripts/bootsy/translations.js +8 -0
- data/app/assets/javascripts/bootsy/wysihtml5.js +9564 -0
- data/app/assets/stylesheets/bootsy.css +3 -0
- data/app/assets/stylesheets/bootsy/bootstrap-submenu.css +47 -0
- data/app/assets/stylesheets/bootsy/bootstrap-wysihtml5.css +102 -0
- data/app/assets/stylesheets/bootsy/bootsy.css +161 -0
- data/app/controllers/bootsy/application_controller.rb +7 -0
- data/app/controllers/bootsy/images_controller.rb +80 -0
- data/app/helpers/bootsy/application_helper.rb +11 -0
- data/app/uploaders/bootsy/image_uploader.rb +35 -0
- data/app/views/bootsy/images/_image.html.erb +43 -0
- data/app/views/bootsy/images/_modal.html.erb +28 -0
- data/app/views/bootsy/images/_new.html.erb +8 -0
- data/config/cucumber.yml +8 -0
- data/config/locales/en.yml +27 -0
- data/config/locales/pt-BR.yml +27 -0
- data/config/routes.rb +11 -0
- data/db/migrate/20120624171333_create_bootsy_images.rb +9 -0
- data/db/migrate/20120628124845_create_bootsy_image_galleries.rb +8 -0
- data/lib/bootsy-rails3.rb +66 -0
- data/lib/bootsy/activerecord/image.rb +11 -0
- data/lib/bootsy/activerecord/image_gallery.rb +8 -0
- data/lib/bootsy/container.rb +31 -0
- data/lib/bootsy/core_ext.rb +2 -0
- data/lib/bootsy/engine.rb +31 -0
- data/lib/bootsy/form_builder.rb +7 -0
- data/lib/bootsy/form_helper.rb +68 -0
- data/lib/bootsy/simple_form/bootsy_input.rb +11 -0
- data/lib/bootsy/version.rb +3 -0
- data/lib/generators/bootsy/USAGE +12 -0
- data/lib/generators/bootsy/install_generator.rb +50 -0
- data/lib/generators/bootsy/templates/bootsy.rb +64 -0
- data/lib/tasks/bootsy_tasks.rake +4 -0
- data/lib/tasks/cucumber.rake +65 -0
- metadata +137 -0
@@ -0,0 +1,43 @@
|
|
1
|
+
<div class="bootsy-image dropdown col-md-2" data-id="<%= image.id %>">
|
2
|
+
<%= link_to image_tag(image.image_file.thumb.url), '#', class: 'thumbnail',
|
3
|
+
data: { toggle: 'dropdown' } %>
|
4
|
+
|
5
|
+
<ul class="dropdown-menu" role="menu">
|
6
|
+
<li role="presentation" class="dropdown-header"><%= t 'bootsy.image.size' %></li>
|
7
|
+
|
8
|
+
<% Bootsy.image_versions_available.each do |size| %>
|
9
|
+
<li role="presentation" class="dropdown dropdown-submenu">
|
10
|
+
<%= link_to '#', tabindex: '-1', role: 'menuitem', data: { toggle: 'dropdown' } do %>
|
11
|
+
<i class="icon-picture"></i>
|
12
|
+
|
13
|
+
<%= t size, scope: 'bootsy.image' %>
|
14
|
+
<% end %>
|
15
|
+
|
16
|
+
<ul class="dropdown-menu" role="menu">
|
17
|
+
<% [:left, :right, :inline].each do |position| %>
|
18
|
+
<li role="presentation">
|
19
|
+
<%= link_to '#', class: 'insert', tabindex: '-1', role: 'menuitem',
|
20
|
+
data: { image_size: size.to_s, position: position.to_s} do %>
|
21
|
+
<%= t position, scope: 'bootsy.image.position' %>
|
22
|
+
<% end %>
|
23
|
+
</li>
|
24
|
+
<% end %>
|
25
|
+
</ul>
|
26
|
+
</li>
|
27
|
+
<% end %>
|
28
|
+
|
29
|
+
<% if Bootsy.allow_destroy %>
|
30
|
+
<li role="presentation" class="divider"></li>
|
31
|
+
|
32
|
+
<li role="presentation">
|
33
|
+
<%= link_to image, method: :delete, remote: true,
|
34
|
+
data: { confirm: t('bootsy.image.confirm.destroy'), type: 'json' },
|
35
|
+
tabindex: '-1', role: 'menuitem', class: 'destroy-btn' do %>
|
36
|
+
<i class="icon-trash"></i>
|
37
|
+
|
38
|
+
<%= t('bootsy.action.destroy') %>
|
39
|
+
<% end %>
|
40
|
+
</li>
|
41
|
+
<% end %>
|
42
|
+
</ul>
|
43
|
+
</div>
|
@@ -0,0 +1,28 @@
|
|
1
|
+
<div class="modal fade bootsy-modal" tabindex="-1"
|
2
|
+
role="dialog" aria-hidden="true" data-no-turbolink
|
3
|
+
data-gallery-id="<%= container.bootsy_image_gallery_id %>">
|
4
|
+
<div class="modal-dialog">
|
5
|
+
<div class="modal-content">
|
6
|
+
<div class="modal-header">
|
7
|
+
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
|
8
|
+
|
9
|
+
<h3 class="modal-title"><%= t 'bootsy.image.p' %></h3>
|
10
|
+
</div>
|
11
|
+
|
12
|
+
<div class="modal-body">
|
13
|
+
<div class="alert alert-info bootsy-empty-alert">
|
14
|
+
<%= t 'bootsy.no_images_uploaded' %>
|
15
|
+
</div>
|
16
|
+
|
17
|
+
<div class="row bootsy-gallery"></div>
|
18
|
+
|
19
|
+
<%= image_tag 'bootsy/gallery-loader.gif', class: 'bootsy-gallery-loader' %>
|
20
|
+
|
21
|
+
<%= refresh_btn %>
|
22
|
+
</div>
|
23
|
+
|
24
|
+
<div class="modal-footer">
|
25
|
+
</div>
|
26
|
+
</div>
|
27
|
+
</div>
|
28
|
+
</div>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<%= form_for([bootsy, resource_or_nil(gallery), image], remote: true,
|
2
|
+
html: { multipart: true, class: 'bootsy-upload-form form-inline' }, data: { type: 'json' }) do |f| %>
|
3
|
+
<%= hidden_field_tag :authenticity_token, form_authenticity_token %>
|
4
|
+
|
5
|
+
<%= image_tag 'bootsy/upload-loader.gif', class: 'bootsy-upload-loader' %>
|
6
|
+
|
7
|
+
<%= f.file_field :image_file, title: t('bootsy.action.upload') %>
|
8
|
+
<% end %>
|
data/config/cucumber.yml
ADDED
@@ -0,0 +1,8 @@
|
|
1
|
+
<%
|
2
|
+
rerun = File.file?('rerun.txt') ? IO.read('rerun.txt') : ""
|
3
|
+
rerun_opts = rerun.to_s.strip.empty? ? "--format #{ENV['CUCUMBER_FORMAT'] || 'progress'} features" : "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} #{rerun}"
|
4
|
+
std_opts = "--format #{ENV['CUCUMBER_FORMAT'] || 'pretty'} --strict --tags ~@wip"
|
5
|
+
%>
|
6
|
+
default: <%= std_opts %> features
|
7
|
+
wip: --tags @wip:3 --wip features
|
8
|
+
rerun: <%= rerun_opts %> --format rerun --out rerun.txt --strict --tags ~@wip
|
@@ -0,0 +1,27 @@
|
|
1
|
+
en:
|
2
|
+
bootsy:
|
3
|
+
action:
|
4
|
+
refresh: Refresh
|
5
|
+
destroy: Delete
|
6
|
+
close: Close
|
7
|
+
load: Load
|
8
|
+
upload: Upload New Image
|
9
|
+
image_gallery: Image Gallery
|
10
|
+
image:
|
11
|
+
s: Image
|
12
|
+
p: Images
|
13
|
+
size: Size
|
14
|
+
large: Large
|
15
|
+
medium: Medium
|
16
|
+
small: Small
|
17
|
+
original: Original
|
18
|
+
new: New image
|
19
|
+
confirm:
|
20
|
+
destroy: Are you sure you want to delete this image?
|
21
|
+
position:
|
22
|
+
left: Left
|
23
|
+
right: Right
|
24
|
+
inline: Inline
|
25
|
+
no_images_uploaded: There are currently no uploaded images.
|
26
|
+
js:
|
27
|
+
alert_unsaved: You have unsaved changes.
|
@@ -0,0 +1,27 @@
|
|
1
|
+
pt-BR:
|
2
|
+
bootsy:
|
3
|
+
action:
|
4
|
+
refresh: Atualizar
|
5
|
+
destroy: Apagar
|
6
|
+
close: Fechar
|
7
|
+
load: Carregar
|
8
|
+
upload: Nova imagem
|
9
|
+
image_gallery: Galeria de Imagens
|
10
|
+
image:
|
11
|
+
s: Imagem
|
12
|
+
p: Imagens
|
13
|
+
size: Tamanho
|
14
|
+
large: Grande
|
15
|
+
medium: Médio
|
16
|
+
small: Pequeno
|
17
|
+
original: Original
|
18
|
+
new: Nova imagem
|
19
|
+
confirm:
|
20
|
+
destroy: Tem certeza que deseja apagar esta imagem?
|
21
|
+
position:
|
22
|
+
left: Esquerda
|
23
|
+
right: Direita
|
24
|
+
inline: Mesma linha
|
25
|
+
no_images_uploaded: Não existem imagens salvas.
|
26
|
+
js:
|
27
|
+
alert_unsaved: As suas modificações ainda não foram gravadas.
|
data/config/routes.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
Bootsy::Engine.routes.draw do
|
2
|
+
resources :image_galleries, only: [] do
|
3
|
+
resources :images, only: [:index, :create, :update, :destroy]
|
4
|
+
end
|
5
|
+
|
6
|
+
file_routes = [:index, :create, :update]
|
7
|
+
|
8
|
+
file_routes << :destroy if Bootsy.allow_destroy
|
9
|
+
|
10
|
+
resources :images, only: file_routes
|
11
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
require 'carrierwave'
|
2
|
+
require 'remotipart'
|
3
|
+
require 'bootsy/engine'
|
4
|
+
require 'bootsy/container'
|
5
|
+
require 'bootsy/form_helper'
|
6
|
+
require 'bootsy/form_builder'
|
7
|
+
require 'bootsy/core_ext'
|
8
|
+
|
9
|
+
autoload :BootsyInput, 'bootsy/simple_form/bootsy_input'
|
10
|
+
|
11
|
+
module Bootsy
|
12
|
+
## CONFIGURATION OPTIONS
|
13
|
+
|
14
|
+
# Default editor options
|
15
|
+
mattr_accessor :editor_options
|
16
|
+
@@editor_options = {
|
17
|
+
font_styles: true,
|
18
|
+
emphasis: true,
|
19
|
+
lists: true,
|
20
|
+
html: false,
|
21
|
+
link: true,
|
22
|
+
image: true,
|
23
|
+
color: true
|
24
|
+
}
|
25
|
+
|
26
|
+
# Image versions available
|
27
|
+
mattr_accessor :image_versions_available
|
28
|
+
@@image_versions_available = [:small, :medium, :large, :original]
|
29
|
+
|
30
|
+
# Whether user can destroy uploaded files
|
31
|
+
mattr_accessor :allow_destroy
|
32
|
+
@@allow_destroy = true
|
33
|
+
|
34
|
+
# Settings for small images
|
35
|
+
mattr_accessor :small_image
|
36
|
+
@@small_image = {width: 160, height: 160}
|
37
|
+
|
38
|
+
# Settings for medium images
|
39
|
+
mattr_accessor :medium_image
|
40
|
+
@@medium_image = {width: 360, height: 360}
|
41
|
+
|
42
|
+
# Settings for large images
|
43
|
+
mattr_accessor :large_image
|
44
|
+
@@large_image = {width: 760, height: 760}
|
45
|
+
|
46
|
+
# Settings for the original version of images
|
47
|
+
mattr_accessor :original_image
|
48
|
+
@@original_image = {}
|
49
|
+
|
50
|
+
# Storage mode
|
51
|
+
mattr_accessor :storage
|
52
|
+
@@storage = :file
|
53
|
+
|
54
|
+
# Store directory (inside 'public')
|
55
|
+
mattr_accessor :store_dir
|
56
|
+
@@store_dir = 'uploads'
|
57
|
+
|
58
|
+
|
59
|
+
## SETUP
|
60
|
+
|
61
|
+
# Default way to setup Bootsy. Run rails generate bootsy:install
|
62
|
+
# to create a fresh initializer with all configuration values.
|
63
|
+
def self.setup
|
64
|
+
yield self
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,8 @@
|
|
1
|
+
module Bootsy
|
2
|
+
class ImageGallery < ActiveRecord::Base
|
3
|
+
belongs_to :bootsy_resource, polymorphic: true
|
4
|
+
has_many :images, dependent: :destroy
|
5
|
+
|
6
|
+
scope :destroy_orphans, ->(time_limit) { where('created_at < ? AND bootsy_resource_id IS NULL', time_limit).destroy_all }
|
7
|
+
end
|
8
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'active_support/concern'
|
2
|
+
|
3
|
+
module Bootsy
|
4
|
+
module Container
|
5
|
+
|
6
|
+
extend ActiveSupport::Concern
|
7
|
+
|
8
|
+
included do
|
9
|
+
class_eval do
|
10
|
+
has_one :bootsy_image_gallery, class_name: 'Bootsy::ImageGallery', as: :bootsy_resource, dependent: :destroy
|
11
|
+
|
12
|
+
def bootsy_image_gallery_id
|
13
|
+
if self.bootsy_image_gallery.nil?
|
14
|
+
nil
|
15
|
+
else
|
16
|
+
self.bootsy_image_gallery.id
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
def bootsy_image_gallery_id=(value)
|
21
|
+
if self.bootsy_image_gallery.nil? && !value.blank?
|
22
|
+
ig = Bootsy::ImageGallery.find(value)
|
23
|
+
self.bootsy_image_gallery = ig
|
24
|
+
ig.bootsy_resource = self
|
25
|
+
ig.save
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
module Bootsy
|
2
|
+
class Engine < Rails::Engine
|
3
|
+
|
4
|
+
isolate_namespace Bootsy
|
5
|
+
|
6
|
+
config.generators do |g|
|
7
|
+
g.test_framework :rspec
|
8
|
+
g.integration_tool :rspec
|
9
|
+
end
|
10
|
+
|
11
|
+
config.to_prepare do
|
12
|
+
ActionController::Base.class_eval do
|
13
|
+
helper Bootsy::ApplicationHelper
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
config.after_initialize do
|
18
|
+
if defined?(BOOTSY_ORM)
|
19
|
+
orm = BOOTSY_ORM
|
20
|
+
else
|
21
|
+
orm = :activerecord
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
case orm
|
26
|
+
when :activerecord
|
27
|
+
Dir[File.expand_path('../activerecord/*.rb', __FILE__)].each {|f| require f }
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Bootsy
|
2
|
+
module FormHelper
|
3
|
+
def bootsy_area(object_name, method, options = {})
|
4
|
+
container = options[:container] || options[:object]
|
5
|
+
|
6
|
+
output = self.text_area(object_name, method, text_area_options(options))
|
7
|
+
|
8
|
+
if output.present? && enable_uploader?(options)
|
9
|
+
container.bootsy_image_gallery_id ||= Bootsy::ImageGallery.create!.id
|
10
|
+
|
11
|
+
output += self.render('bootsy/images/modal', container: container)
|
12
|
+
|
13
|
+
if container.new_record?
|
14
|
+
output += self.hidden_field(object_name, :bootsy_image_gallery_id, class: 'bootsy_image_gallery_id')
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
output
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
|
23
|
+
def enable_uploader?(options)
|
24
|
+
if options[:uploader] == false
|
25
|
+
false
|
26
|
+
elsif options[:container].is_a?(Container)
|
27
|
+
true
|
28
|
+
elsif options[:container].blank? && options[:object].is_a?(Container)
|
29
|
+
true
|
30
|
+
else
|
31
|
+
false
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
def tag_class(options)
|
36
|
+
classes = if options[:class].blank?
|
37
|
+
[]
|
38
|
+
elsif options[:class].kind_of?(Array)
|
39
|
+
options[:class]
|
40
|
+
else
|
41
|
+
[options[:class]]
|
42
|
+
end
|
43
|
+
|
44
|
+
classes << 'bootsy_text_area'
|
45
|
+
end
|
46
|
+
|
47
|
+
def data_options(options)
|
48
|
+
(options[:data] || {}).merge Hash[ bootsy_options(options).map { |k,v| ["bootsy-#{k}", v] } ]
|
49
|
+
end
|
50
|
+
|
51
|
+
def bootsy_options(options)
|
52
|
+
Bootsy.editor_options.
|
53
|
+
merge(options[:editor_options] || {}).
|
54
|
+
merge(uploader: enable_uploader?(options))
|
55
|
+
end
|
56
|
+
|
57
|
+
def text_area_options(options)
|
58
|
+
options.except(
|
59
|
+
:container,
|
60
|
+
:uploader,
|
61
|
+
:editor_options
|
62
|
+
).merge(
|
63
|
+
data: data_options(options),
|
64
|
+
class: tag_class(options)
|
65
|
+
)
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'simple_form'
|
2
|
+
|
3
|
+
class BootsyInput < SimpleForm::Inputs::Base
|
4
|
+
enable :placeholder, :maxlength, :container, :editor_options, :uploader
|
5
|
+
|
6
|
+
def input
|
7
|
+
bootsy_params = [:editor_options, :container, :uploader]
|
8
|
+
input_html_options.merge! input_options.select {|k,v| bootsy_params.include? k }
|
9
|
+
@builder.bootsy_area attribute_name, input_html_options
|
10
|
+
end
|
11
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
Description:
|
2
|
+
Adds Bootsy routes, locale and assets to your application.
|
3
|
+
|
4
|
+
Example:
|
5
|
+
rails generate bootsy:install
|
6
|
+
|
7
|
+
This will create:
|
8
|
+
route mount Bootsy::Engine => '/bootsy', as: 'bootsy'
|
9
|
+
create config/locales/bootsy.en.yml
|
10
|
+
insert app/assets/javascripts/application.js
|
11
|
+
insert app/assets/stylesheets/application.css
|
12
|
+
|