easy_modal_window 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 1155b46ab7481647db5c3ddfe7e7208d68035f78
4
+ data.tar.gz: 16e862310313f92a54cb5d3053fb8761ffd0f8d5
5
+ SHA512:
6
+ metadata.gz: ba2ed88b00202d70290041c91543ece201b4c62f54eae65f81b639dbe40a9f80c1bbbb30d960d44a5ba3a015c9d45188577210eb6d492fd58f060efa78e01bce
7
+ data.tar.gz: 6762fda03e88ec40fe573e9f279c3916946919b6c981d52c72f7468dca9ae114f77608f13f7ea59b02438c31f59e839202a068077b9130a68bab95373bd0bf60
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ .idea/*
7
+ Gemfile.lock
8
+ InstalledFiles
9
+ _yardoc
10
+ coverage
11
+ doc/
12
+ lib/bundler/man
13
+ pkg
14
+ rdoc
15
+ spec/reports
16
+ test/tmp
17
+ test/version_tmp
18
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,9 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'rails'#, '~> 3.2.13'
4
+ gem 'jquery-rails'#, '~> 2.0.2'
5
+ gem 'haml-rails'
6
+
7
+ gem 'error_messages_container'
8
+
9
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Ivan Zabrovskiy
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,29 @@
1
+ # EasyModalWindow
2
+
3
+ This is wrapper for jQuery-UI Dialog. Additionaly it contain several templates for render errors from ActiveRecord and ErrorMessagesContainer.
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'easy_modal_window', git: 'https://github.com/Loriowar/easy_modal_window.git'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install easy_modal_window
18
+
19
+ ## Usage
20
+
21
+ Coming soon
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it ( http://github.com/Loriowar/easy_modal_window/fork )
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,10 @@
1
+ -# modal_options - local variable (class: EasyModalWindow::Dialog)
2
+
3
+ - if modal_options.object.present? && modal_options.object.errors.blank?
4
+ %h3
5
+ = modal_options.success_message
6
+ - else
7
+ %ul{class: modal_options.container_class}
8
+ - modal_options.object.errors.full_messages.each do |message|
9
+ %li{class: modal_options.element_class}
10
+ = message
@@ -0,0 +1,28 @@
1
+ <%# modal_options - local variable (class: EasyModalWindow::Dialog) %>
2
+
3
+ var $modalWindow = $('<%= modal_options.window_selector %>');
4
+
5
+ $modalWindow.html("<%= j render template: modal_options.render_template,
6
+ formats: modal_options.formats %>");
7
+ var $titleElement = $modalWindow.find('<%= modal_options.title_selector %>');
8
+ var title = $titleElement.text();
9
+ $titleElement.hide();
10
+ $modalWindow.dialog({
11
+ resizable: <%= modal_options.resizable %>,
12
+ modal: true,
13
+ height: '<%= modal_options.height %>',
14
+ width: '<%= modal_options.width %>',
15
+ title: title,
16
+ <% if modal_options.before_close[:condition] %>
17
+ beforeClose: function() {<%= modal_options.before_close[:action].html_safe %>},
18
+ <% end %>
19
+ buttons: {
20
+ <% modal_options.buttons.each do |button_options| %>
21
+ <% if button_options[:condition] %>
22
+ "<%= button_options[:name] %>": function() {
23
+ <%= button_options[:action].html_safe %>
24
+ },
25
+ <% end %>
26
+ <% end %>
27
+ }
28
+ });
@@ -0,0 +1,15 @@
1
+ -# modal_options - local variable (class: EasyModalWindow::Dialog)
2
+
3
+ - if modal_options.object.blank?
4
+ %h3
5
+ = modal_options.success_message
6
+ - else
7
+ %ul{class: modal_options.container_class}
8
+ - modal_options.object.all_messages.each do |group_name, messages|
9
+ %li{class: modal_options.element_class}
10
+ %div{class: modal_options.errors_group_class}
11
+ = modal_options.object.name_for_group(group_name)
12
+ %ul
13
+ - messages.each do |message|
14
+ %li
15
+ = message
@@ -0,0 +1,23 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'easy_modal_window/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "easy_modal_window"
8
+ spec.version = EasyModalWindow::VERSION
9
+ spec.authors = ["Ivan Zabrovskiy"]
10
+ spec.email = ["loriowar@gmail.com"]
11
+ spec.summary = %q{Small wrapper for jQuery-UI Dialog}
12
+ spec.description = %q{This is wrapper for jQuery-UI Dialog. Additionaly it contain several templates for render errors from ActiveRecord and ErrorMessagesContainer.}
13
+ spec.homepage = "https://github.com/Loriowar/easy_modal_window.git"
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_development_dependency "bundler", "~> 1.5"
22
+ spec.add_development_dependency "rake"
23
+ end
@@ -0,0 +1,28 @@
1
+ module EasyModalWindow
2
+ module DialogHelpers
3
+
4
+ def render_base_dialog(options)
5
+ render_modal_window(options.merge(view: 'base_dialog', format: :js))
6
+ end
7
+
8
+ def render_active_record_result(options)
9
+ render_modal_window(options.merge(view: 'active_record_result', format: :html))
10
+ end
11
+
12
+ def render_errors_container_result(options)
13
+ render_modal_window(options.merge(view: 'errors_container_result', format: :html))
14
+ end
15
+
16
+ private
17
+
18
+ def render_modal_window(options)
19
+ if options.has_key?(:view)
20
+ dialog = EasyModalWindow::Dialog.new(options)
21
+ render template: "easy_modal_window/#{options[:view]}",
22
+ locals: {modal_options: dialog},
23
+ formats: options[:format] || [:js]
24
+ end
25
+ end
26
+
27
+ end
28
+ end
@@ -0,0 +1,6 @@
1
+ require 'easy_modal_window/helpers/dialog_helpers.rb'
2
+
3
+ module EasyModalWindow::DialogHelpers; end
4
+
5
+ ActionView::Base.send :include, EasyModalWindow::DialogHelpers
6
+ ActionController::Base.prepend_view_path File.dirname(__FILE__) + '/../../app/views'
@@ -0,0 +1,3 @@
1
+ module EasyModalWindow
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,83 @@
1
+ require 'easy_modal_window/version'
2
+ require 'easy_modal_window/helpers'
3
+
4
+ module EasyModalWindow
5
+ class Dialog
6
+
7
+ attr_reader :modal_options
8
+
9
+ ALLOVED_OPTIONS = [:window_selector, :title_selector, :render_template, :formats,
10
+ :resizable, :height, :width, :buttons, :before_close, :success_message,
11
+ :object, :container_class, :element_class, :errors_group_class].freeze
12
+
13
+ def initialize(args)
14
+ @modal_options = {}
15
+ @modal_options[:window_selector] = '#ajax-modal'
16
+ @modal_options[:title_selector] = 'h3.title'
17
+ @modal_options[:render_template] = ''
18
+ @modal_options[:formats] = [:html]
19
+ @modal_options[:resizable] = true
20
+ @modal_options[:height] = 'auto'
21
+ @modal_options[:width] = 'auto'
22
+ # hash with button descriptions: {first_button: {name: 'Name',
23
+ # condition: -> {...},
24
+ # action: 'location.reload();'},
25
+ # second_button: ...}
26
+ @modal_options[:buttons] = {}
27
+ # dialog callbacks
28
+ # {condition: ->{...}, action: '...'}
29
+ @modal_options[:before_close] = {}
30
+
31
+ # options for result templates
32
+ @modal_options[:success_message] = 'All right'
33
+ @modal_options[:object] = nil
34
+ @modal_options[:container_class] = ''
35
+ @modal_options[:element_class] = ''
36
+ @modal_options[:errors_group_class] = ''
37
+
38
+ @modal_options.merge!(args.slice(*EasyModalWindow::Dialog::ALLOVED_OPTIONS))
39
+ end
40
+
41
+ (ALLOVED_OPTIONS - [:before_close, :buttons]).each do |method|
42
+ class_eval <<-EOT, __FILE__, __LINE__ + 1
43
+ def #{method}
44
+ @modal_options[:#{method}]
45
+ end
46
+ EOT
47
+ end
48
+
49
+ # TODO: simplify this method
50
+ def before_close
51
+ result = {}
52
+ if @modal_options[:before_close].has_key?(:action) && @modal_options[:before_close][:action].present?
53
+ result[:action] = @modal_options[:before_close][:action]
54
+ else
55
+ result[:condition] = false
56
+ result[:action] = ''
57
+ return result
58
+ end
59
+
60
+ result[:condition] = @modal_options[:before_close][:condition].nil? || value_of(@modal_options[:before_close][:condition])
61
+
62
+ result
63
+ end
64
+
65
+ def buttons
66
+ @modal_options[:buttons].inject([]) do |h, v|
67
+ option = {}
68
+ option[:name] = v.last[:name] || 'unknown'
69
+ option[:condition] = value_of(v.last[:condition]).nil? || value_of(v.last[:condition])
70
+ option[:action] = v.last[:action] || ''
71
+ h << option
72
+ h
73
+ end
74
+ end
75
+
76
+ private
77
+
78
+ def value_of(var)
79
+ var.is_a?(Proc) ? var.call : var
80
+ end
81
+
82
+ end
83
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: easy_modal_window
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Zabrovskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-09-11 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: '1.5'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ~>
25
+ - !ruby/object:Gem::Version
26
+ version: '1.5'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: This is wrapper for jQuery-UI Dialog. Additionaly it contain several
42
+ templates for render errors from ActiveRecord and ErrorMessagesContainer.
43
+ email:
44
+ - loriowar@gmail.com
45
+ executables: []
46
+ extensions: []
47
+ extra_rdoc_files: []
48
+ files:
49
+ - .gitignore
50
+ - Gemfile
51
+ - LICENSE.txt
52
+ - README.md
53
+ - Rakefile
54
+ - app/views/easy_modal_window/active_record_result.html.haml
55
+ - app/views/easy_modal_window/base_dialog.js.erb
56
+ - app/views/easy_modal_window/errors_container_result.html.haml
57
+ - easy_modal_window.gemspec
58
+ - lib/easy_modal_window.rb
59
+ - lib/easy_modal_window/helpers.rb
60
+ - lib/easy_modal_window/helpers/dialog_helpers.rb
61
+ - lib/easy_modal_window/version.rb
62
+ homepage: https://github.com/Loriowar/easy_modal_window.git
63
+ licenses:
64
+ - MIT
65
+ metadata: {}
66
+ post_install_message:
67
+ rdoc_options: []
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - '>='
73
+ - !ruby/object:Gem::Version
74
+ version: '0'
75
+ required_rubygems_version: !ruby/object:Gem::Requirement
76
+ requirements:
77
+ - - '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 2.0.2
83
+ signing_key:
84
+ specification_version: 4
85
+ summary: Small wrapper for jQuery-UI Dialog
86
+ test_files: []
87
+ has_rdoc: