bootsy 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (36) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.md +79 -0
  3. data/Rakefile +27 -0
  4. data/app/assets/javascripts/bootsy/application.js +4 -0
  5. data/app/assets/javascripts/bootsy/bootstrap-wysihtml5.js +349 -0
  6. data/app/assets/javascripts/bootsy/bootsy.js +61 -0
  7. data/app/assets/javascripts/bootsy/wysihtml5.js +9521 -0
  8. data/app/assets/stylesheets/bootsy/application.css +4 -0
  9. data/app/assets/stylesheets/bootsy/bootstrap-wysihtml5.css +44 -0
  10. data/app/controllers/bootsy/application_controller.rb +4 -0
  11. data/app/controllers/bootsy/images_controller.rb +58 -0
  12. data/app/helpers/bootsy/application_helper.rb +8 -0
  13. data/app/helpers/bootsy/images_helper.rb +4 -0
  14. data/app/models/bootsy/image.rb +11 -0
  15. data/app/models/bootsy/image_gallery.rb +6 -0
  16. data/app/uploaders/image_uploader.rb +39 -0
  17. data/app/views/bootsy/images/_index.html.erb +22 -0
  18. data/app/views/bootsy/images/_modal.html.erb +12 -0
  19. data/app/views/bootsy/images/_new.html.erb +23 -0
  20. data/app/views/bootsy/images/create.js.erb +3 -0
  21. data/app/views/bootsy/images/destroy.js.erb +1 -0
  22. data/app/views/bootsy/images/index.js.erb +2 -0
  23. data/config/bootsy.yml +0 -0
  24. data/config/locales/en.yml +19 -0
  25. data/config/locales/pt-BR.yml +19 -0
  26. data/config/routes.rb +7 -0
  27. data/db/migrate/20120624171333_create_bootsy_images.rb +9 -0
  28. data/db/migrate/20120628124845_create_bootsy_image_galleries.rb +8 -0
  29. data/lib/bootsy.rb +8 -0
  30. data/lib/bootsy/core_ext.rb +34 -0
  31. data/lib/bootsy/engine.rb +16 -0
  32. data/lib/bootsy/media_container.rb +27 -0
  33. data/lib/bootsy/version.rb +3 -0
  34. data/lib/generators/install_generator.rb +27 -0
  35. data/lib/tasks/bootsy_tasks.rake +4 -0
  36. metadata +248 -0
@@ -0,0 +1,4 @@
1
+ /*
2
+ *= require bootsy/bootstrap-wysihtml5
3
+ *= require_tree .
4
+ */
@@ -0,0 +1,44 @@
1
+ ul.wysihtml5-toolbar {
2
+ margin: 0;
3
+ padding: 0;
4
+ display: block;
5
+ }
6
+
7
+ ul.wysihtml5-toolbar::after {
8
+ clear: both;
9
+ display: table;
10
+ content: "";
11
+ }
12
+
13
+ ul.wysihtml5-toolbar > li {
14
+ float: left;
15
+ display: list-item;
16
+ list-style: none;
17
+ margin: 0 5px 10px 0;
18
+ }
19
+
20
+ ul.wysihtml5-toolbar a[data-wysihtml5-command=bold] {
21
+ font-weight: bold;
22
+ }
23
+
24
+ ul.wysihtml5-toolbar a[data-wysihtml5-command=italic] {
25
+ font-style: italic;
26
+ }
27
+
28
+ ul.wysihtml5-toolbar a[data-wysihtml5-command=underline] {
29
+ text-decoration: underline;
30
+ }
31
+
32
+ ul.wysihtml5-toolbar a.btn.wysihtml5-command-active {
33
+ background-image: none;
34
+ -webkit-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15),0 1px 2px rgba(0, 0, 0, 0.05);
35
+ -moz-box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15),0 1px 2px rgba(0, 0, 0, 0.05);
36
+ box-shadow: inset 0 2px 4px rgba(0, 0, 0, 0.15),0 1px 2px rgba(0, 0, 0, 0.05);
37
+ background-color: #E6E6E6;
38
+ background-color: #D9D9D9 9;
39
+ outline: 0;
40
+ }
41
+
42
+ ul.wysihtml5-commands-disabled .dropdown-menu {
43
+ display: none !important;
44
+ }
@@ -0,0 +1,4 @@
1
+ module Bootsy
2
+ class ApplicationController < ActionController::Base
3
+ end
4
+ end
@@ -0,0 +1,58 @@
1
+ require_dependency "bootsy/application_controller"
2
+
3
+ module Bootsy
4
+ class ImagesController < ApplicationController
5
+ # GET /images
6
+ # GET /images.json
7
+ def index
8
+ @gallery = find_gallery
9
+ @images = @gallery.images
10
+
11
+ respond_to do |format|
12
+ format.js
13
+ format.html # index.html.erb
14
+ format.json { render json: @images }
15
+ end
16
+ end
17
+
18
+ # POST /images
19
+ # POST /images.json
20
+ def create
21
+ @gallery = find_gallery
22
+ @gallery.save! unless @gallery.persisted?
23
+ @image = @gallery.images.new params[:image]
24
+
25
+ respond_to do |format|
26
+ if @image.save
27
+ @images = @gallery.images
28
+ format.js
29
+ format.json { render json: @image, status: :created, location: @image }
30
+ else
31
+ format.json { render json: @image.errors, status: :unprocessable_entity }
32
+ end
33
+ end
34
+ end
35
+
36
+ # DELETE /images/1
37
+ # DELETE /images/1.json
38
+ def destroy
39
+ @image = Image.find(params[:id])
40
+ @image.destroy
41
+
42
+ respond_to do |format|
43
+ format.js
44
+ format.html { redirect_to images_url }
45
+ format.json { head :no_content }
46
+ end
47
+ end
48
+
49
+ private
50
+ def find_gallery
51
+ begin
52
+ return ImageGallery.find params[:image_gallery_id]
53
+ rescue
54
+ return ImageGallery.new
55
+ end
56
+ end
57
+ end
58
+ end
@@ -0,0 +1,8 @@
1
+ module Bootsy
2
+ module ApplicationHelper
3
+ def refresh_btn gallery, collection
4
+ gallery = nil unless gallery.nil? || gallery.persisted?
5
+ link_to t('bootsy.refresh'), [bootsy, gallery, collection], remote: true, :class => 'btn btn-mini refresh_btn'
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,4 @@
1
+ module Bootsy
2
+ module ImagesHelper
3
+ end
4
+ end
@@ -0,0 +1,11 @@
1
+ module Bootsy
2
+ class Image < ActiveRecord::Base
3
+ belongs_to :image_gallery
4
+
5
+ mount_uploader :image_file, ImageUploader
6
+
7
+ attr_accessible :image_file
8
+
9
+ validates_presence_of :image_file, :image_gallery_id
10
+ end
11
+ end
@@ -0,0 +1,6 @@
1
+ module Bootsy
2
+ class ImageGallery < ActiveRecord::Base
3
+ belongs_to :bootsy_resource, polymorphic: true
4
+ has_many :images, dependent: :destroy
5
+ end
6
+ end
@@ -0,0 +1,39 @@
1
+ # encoding: utf-8
2
+
3
+ class ImageUploader < CarrierWave::Uploader::Base
4
+
5
+ include CarrierWave::MiniMagick
6
+
7
+ include Sprockets::Helpers::RailsHelper
8
+ include Sprockets::Helpers::IsolatedHelper
9
+
10
+ storage :file
11
+
12
+
13
+ def store_dir
14
+ "uploads/#{model.class.to_s.underscore}/#{model.id}"
15
+ end
16
+
17
+ # Process files as they are uploaded:
18
+ process :resize_to_limit => [940, 940]
19
+
20
+ version :large do
21
+ process :resize_to_fit => [600, 600]
22
+ end
23
+
24
+ version :medium do
25
+ process :resize_to_fit => [300, 300]
26
+ end
27
+
28
+ version :small do
29
+ process :resize_to_fit => [160, 160]
30
+ end
31
+
32
+ version :thumb do
33
+ process :resize_to_fill => [60, 60]
34
+ end
35
+
36
+ def extension_white_list
37
+ %w(jpg jpeg gif png)
38
+ end
39
+ end
@@ -0,0 +1,22 @@
1
+ <ul class="thumbnails">
2
+ <% images.each do |image| %>
3
+ <li class="span1 dropdown">
4
+ <%= link_to image_tag(image.image_file.thumb.url), '#', :class => 'thumbnail', data: { toggle: 'dropdown'} %>
5
+ <ul class="dropdown-menu">
6
+ <li class="nav-header"><%= t 'bootsy.image.size' %></li>
7
+ <li><%= link_to t('bootsy.image.small'), '#', :class => 'insert', data: { :'image-size' => 'small'} %></li>
8
+ <li><%= link_to t('bootsy.image.medium'), '#', :class => 'insert', data: { :'image-size' => 'medium'} %></li>
9
+ <li><%= link_to t('bootsy.image.large'), '#', :class => 'insert', data: { :'image-size' => 'large'} %></li>
10
+ <li><%= link_to t('bootsy.image.original'), '#', :class => 'insert', data: { :'image-size' => 'original'} %></li>
11
+ <li class="divider"></li>
12
+ <li><%= link_to t('bootsy.action.destroy'), image, method: :delete, remote: true, data: { confirm: t('bootsy.image.confirm.destroy')}, :class => 'destroy_btn' %></li>
13
+ </ul>
14
+ </li>
15
+ <% end %>
16
+ </ul>
17
+
18
+ <%= refresh_btn gallery, :images %>
19
+
20
+ <hr />
21
+
22
+ <%= render 'bootsy/images/new', {image: gallery.images.new } %>
@@ -0,0 +1,12 @@
1
+ <div class="modal hide fade" id="bootsy_image_gallery">
2
+ <div class="modal-header">
3
+ <button type="button" class="close" data-dismiss="modal">×</button>
4
+ <h2><%= t 'bootsy.image.p' %></h2>
5
+ </div>
6
+ <div class="modal-body">
7
+ <%= refresh_btn resource.bootsy_image_gallery, :images %>
8
+ </div>
9
+ <div class="modal-footer">
10
+ <a href="#" class="btn" data-dismiss="modal"><%= t 'bootsy.action.close' %></a>
11
+ </div>
12
+ </div>
@@ -0,0 +1,23 @@
1
+ <h3><%= t 'bootsy.image.new' %></h3>
2
+
3
+ <%= form_for [bootsy, (image.image_gallery || Bootsy::ImageGallery), image], remote: true, html: {:class => 'bootsy'} do |f| %>
4
+ <% if image.errors.any? %>
5
+ <div id="error_explanation">
6
+ <h2><%= pluralize(image.errors.count, "error") %> prohibited this image from being saved:</h2>
7
+
8
+ <ul>
9
+ <% image.errors.full_messages.each do |msg| %>
10
+ <li><%= msg %></li>
11
+ <% end %>
12
+ </ul>
13
+ </div>
14
+ <% end %>
15
+
16
+ <div class="field">
17
+ <%= f.file_field :image_file %>
18
+ </div>
19
+
20
+ <div class="actions">
21
+ <%= f.submit t('bootsy.action.load'), :class => 'btn' %>
22
+ </div>
23
+ <% end %>
@@ -0,0 +1,3 @@
1
+ $('input.bootsy_image_gallery_id').val("<%= @gallery.id %>");
2
+ $('#bootsy_image_gallery div.modal-body').html("<%= j render 'bootsy/images/index', {images: @images, gallery: @gallery}%>");
3
+ $('#bootsy_image_gallery a.refresh_btn').hide();
@@ -0,0 +1 @@
1
+ bootsyRefreshGallery($('#bootsy_image_gallery'));
@@ -0,0 +1,2 @@
1
+ $('#bootsy_image_gallery div.modal-body').html("<%= j render 'bootsy/images/index', {images: @images, gallery: @gallery}%>");
2
+ $('#bootsy_image_gallery a.refresh_btn').hide();
data/config/bootsy.yml ADDED
File without changes
@@ -0,0 +1,19 @@
1
+ en:
2
+ bootsy:
3
+ action:
4
+ refresh: Refresh
5
+ destroy: Destroy
6
+ close: Close
7
+ load: Load
8
+ image_gallery: Image Gallery
9
+ image:
10
+ s: Image
11
+ p: Images
12
+ size: Size
13
+ large: Large
14
+ medium: Medium
15
+ small: Small
16
+ original: Original
17
+ new: New image
18
+ confirm:
19
+ destroy: Are you sure you want do destroy this image?
@@ -0,0 +1,19 @@
1
+ pt-BR:
2
+ bootsy:
3
+ action:
4
+ refresh: Atualizar
5
+ destroy: Apagar
6
+ close: Fechar
7
+ load: Carregar
8
+ image_gallery: Galeria de Imagens
9
+ image:
10
+ s: Imagem
11
+ p: Imagens
12
+ size: Tamanho
13
+ large: Grande
14
+ medium: Médio
15
+ small: Pequeno
16
+ original: Original
17
+ new: Nova imagem
18
+ confirm:
19
+ destroy: Tem certeza que deseja apagar esta imagem?
data/config/routes.rb ADDED
@@ -0,0 +1,7 @@
1
+ Bootsy::Engine.routes.draw do
2
+ resources :image_galleries, only: [] do
3
+ resources :images, only: [:index, :create, :update, :destroy]
4
+ end
5
+
6
+ resources :images, only: [:index, :create, :update, :destroy]
7
+ end
@@ -0,0 +1,9 @@
1
+ class CreateBootsyImages < ActiveRecord::Migration
2
+ def change
3
+ create_table :bootsy_images do |t|
4
+ t.string :image_file
5
+ t.references :image_gallery
6
+ t.timestamps
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,8 @@
1
+ class CreateBootsyImageGalleries < ActiveRecord::Migration
2
+ def change
3
+ create_table :bootsy_image_galleries do |t|
4
+ t.references :bootsy_resource, polymorphic: true
5
+ t.timestamps
6
+ end
7
+ end
8
+ end
data/lib/bootsy.rb ADDED
@@ -0,0 +1,8 @@
1
+ require 'carrierwave'
2
+ require 'remotipart'
3
+ require 'bootsy/engine'
4
+ require 'bootsy/media_container'
5
+ require 'bootsy/core_ext'
6
+
7
+ module Bootsy
8
+ end
@@ -0,0 +1,34 @@
1
+ module Bootsy
2
+ module FormHelper
3
+ def bootsy_area object, method, options = {}
4
+
5
+ resource = options[:resource]
6
+ options.delete :resource
7
+
8
+ if resource.nil? && (object.nil? || object.is_a?(String) || object.is_a?(Array) || object.is_a?(Symbol))
9
+ raise PedroError
10
+ end
11
+
12
+ object_name = object.class.name.underscore
13
+
14
+ output = self.render 'bootsy/images/modal', {resource: resource || object}
15
+ output += self.text_area object_name, method, options.merge({:class => 'bootsy_text_area'}){|key, oldval, newval| "#{oldval} #{newval}"}
16
+ if resource.nil? || (resource == object)
17
+ output += self.hidden_field object_name, :bootsy_image_gallery_id, :class => 'bootsy_image_gallery_id'
18
+ end
19
+ output
20
+ end
21
+
22
+ def self.included arg
23
+ ActionView::Helpers::FormBuilder.send :include, Bootsy::FormBuilder
24
+ end
25
+ end
26
+ end
27
+
28
+ module Bootsy::FormBuilder
29
+ def bootsy_area method, options = {}
30
+ @template.bootsy_area @object, method, options
31
+ end
32
+ end
33
+
34
+ ActionView::Helpers::FormHelper.send :include, Bootsy::FormHelper
@@ -0,0 +1,16 @@
1
+ module Bootsy
2
+ class Engine < ::Rails::Engine
3
+ isolate_namespace Bootsy
4
+
5
+ config.generators do |g|
6
+ g.test_framework :rspec
7
+ g.integration_tool :rspec
8
+ end
9
+
10
+ config.to_prepare do
11
+ ActionController::Base.class_eval do
12
+ helper Bootsy::ApplicationHelper
13
+ end
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ require 'active_support/concern'
2
+
3
+ module Bootsy
4
+ module MediaContainer
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
+ attr_accessible :bootsy_image_gallery_id
12
+
13
+ def bootsy_image_gallery_id
14
+ if self.bootsy_image_gallery.nil?
15
+ return nil
16
+ else
17
+ return self.bootsy_image_gallery.id
18
+ end
19
+ end
20
+
21
+ def bootsy_image_gallery_id=(value)
22
+ self.bootsy_image_gallery = Bootsy::ImageGallery.find value unless value.blank?
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,3 @@
1
+ module Bootsy
2
+ VERSION = "0.0.1"
3
+ end