images_fetcher 1.0.0

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
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
+ tmp
18
+ .DS_Store
data/Gemfile ADDED
@@ -0,0 +1,10 @@
1
+ source 'https://rubygems.org'
2
+
3
+
4
+ # Specify your gem's dependencies in images_fetcher.gemspec
5
+ gemspec
6
+
7
+ gem 'jquery-rails'
8
+ gem 'jquery-ui-rails'
9
+ gem "bootstrap-sass", ">= 2.0.1"
10
+ gem 'haml'
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Alexey Kisel
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,48 @@
1
+ # ImagesFetcher
2
+
3
+ It's a small ruby gem for showing popup with images from selected url
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'jquery-rails'
10
+ gem 'jquery-ui-rails'
11
+ gem "bootstrap-sass", ">= 2.0.1"
12
+ gem 'haml'
13
+
14
+ gem 'images_fetcher', :git => 'git://github.com/spy-a/images_fetcher.git'
15
+
16
+ Add this to your assets/javascripts/application.js file
17
+
18
+ //= require jquery.ui.all
19
+ //= require bootstrap
20
+ //= require images_fetcher
21
+
22
+ Add this to your assets/stylesheets/application.js file
23
+
24
+ *= require jquery.ui.all
25
+ *= require images_fetcher
26
+
27
+ And then execute:
28
+
29
+ $ bundle
30
+
31
+ ## Usage
32
+
33
+ Use helper method init_images_fetcher(link, image_link_input, image_preview='') to initialize images_fetcher functionality
34
+
35
+ For example:
36
+
37
+ &lt;input type=text id=&quot;book_link&quot;&gt; &lt;-- input url with images here<br/>
38
+ &lt;input type=text id=&quot;card_remote_image_url&quot;&gt; &lt;- you get link to image to this field after close popup with images<br/>
39
+ &lt;img id=&quot;remote_image_preview&quot; /&gt; &lt;- optionally, display here selected image<br/>
40
+ &lt;%= init_images_fetcher('#book_link', '#card_remote_image_url', '#remote_image_preview') %&gt;<br/>
41
+
42
+ ## Contributing
43
+
44
+ 1. Fork it
45
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
46
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
47
+ 4. Push to the branch (`git push origin my-new-feature`)
48
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,62 @@
1
+ window.ImagesFetcher = ImagesFetcher =
2
+ init: (wbs, ids,rip)->
3
+ web_link_selector = wbs
4
+ image_destination_selector = ids
5
+ remote_image_preview_selector = rip
6
+
7
+ cur = 0
8
+ count = 0
9
+ images =[]
10
+ context = $('#choose_image')
11
+ $(web_link_selector).change (e) ->
12
+ fetch(this)
13
+
14
+ $(image_destination_selector).change (e) ->
15
+ $(remote_image_preview_selector).attr 'src', $(this).val()
16
+
17
+ $('#prev_image').click (e) ->
18
+ if cur > 0
19
+ cur--
20
+ set_image(cur)
21
+ false
22
+ $('#next_image').click (e) ->
23
+ if cur < count-1
24
+ cur++
25
+ set_image(cur)
26
+ false
27
+
28
+ fetch = (link)->
29
+ url = $(link).val()
30
+ $.ajax '/fetch',
31
+ type: 'GET'
32
+ data:
33
+ url: url
34
+ dataType: 'html'
35
+ error: (jqXHR, textStatus, errorThrown) ->
36
+ success: (data, textStatus, jqXHR) ->
37
+ images = $('img', data).map ->
38
+ $(this).attr('src')
39
+ .filter ->
40
+ this.match(/^http.*(jpg|png)/) != null
41
+ cur = 0
42
+ count = images.length
43
+ if count > 0
44
+ context.find('.count').text(count);
45
+ set_image(0)
46
+ if count > 1
47
+ $('#choose_image').modal
48
+ backdrop : true
49
+ keyboard : true
50
+ show : false
51
+ .css
52
+ 'margin-left' : ->
53
+ -($(@).width() / 2)
54
+
55
+ set_image = (i) ->
56
+ context.find('.current').text(i+1);
57
+ link = images[i]
58
+ $(context).find('#image').attr 'src', link
59
+ $(image_destination_selector).val(link).change()
60
+
61
+
62
+
@@ -0,0 +1,45 @@
1
+ /*
2
+ * This is a manifest file that'll be compiled into application.css, which will include all the files
3
+ * listed below.
4
+ *
5
+ * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
6
+ * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
7
+ *
8
+ * You're free to add application-wide styles to this file and they'll appear at the top of the
9
+ * compiled file, but it's generally better to create a new file per style scope.
10
+ *
11
+ *= require_self
12
+ */
13
+
14
+ @import 'bootstrap';
15
+
16
+ .clear{
17
+ clear:both
18
+ }
19
+
20
+ .left{
21
+ float:left;
22
+ }
23
+
24
+ .right{
25
+ float:right;
26
+ }
27
+
28
+ .btn a:hover {
29
+ background-color: transparent;
30
+ color: inherit;
31
+ text-decoration: none;
32
+ }
33
+
34
+ .hidden {
35
+ display: none !important;
36
+ }
37
+
38
+ #choose_image{
39
+ #image{
40
+ height: 250px;
41
+ }
42
+ .buttons{
43
+ text-align: left;
44
+ }
45
+ }
@@ -0,0 +1,12 @@
1
+ require 'net/http'
2
+ class RequestsController < ActionController::Base
3
+
4
+ caches_action :fetch
5
+
6
+ def fetch
7
+ url = params['url'] || ''
8
+ uri = URI(url)
9
+ render :text => Net::HTTP.get(uri)
10
+ end
11
+
12
+ end
@@ -0,0 +1,8 @@
1
+ module ImagesFetcherHelper
2
+
3
+ def init_images_fetcher(link, image_link_input, image_preview='')
4
+ render('shared/choose_image') +
5
+ render('shared/js', {link: link, image_link_input:image_link_input, image_preview:image_preview})
6
+ end
7
+
8
+ end
@@ -0,0 +1,18 @@
1
+ #choose_image.modal.hide
2
+ .modal-header
3
+ %button.close{ 'data-dismiss' => 'modal' } ×
4
+ %h3 Choose image
5
+ .modal-body
6
+ %img#image
7
+ .modal-footer
8
+ .buttons
9
+ Choose a thumbnail
10
+ %span.counters
11
+ %span.current
12
+ 0
13
+ of
14
+ %span.count
15
+ 0
16
+ = link_to 'Prev', '#', :id => :prev_image
17
+ = link_to 'Next', '#', :id => :next_image
18
+ %a.btn.btn-primary{ href:'#', 'data-dismiss' => 'modal' } Close
@@ -0,0 +1 @@
1
+ = javascript_tag "$(function() { ImagesFetcher.init('#{link}', '#{image_link_input}', '#{image_preview}') });"
data/config/routes.rb ADDED
@@ -0,0 +1,4 @@
1
+ Rails.application.routes.draw do
2
+ match '/fetch' => 'requests#fetch'
3
+ end
4
+
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/images_fetcher/version', __FILE__)
3
+ require File.expand_path('../app/helpers/images_fetcher_helper', __FILE__)
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Alexey Kisel"]
6
+ gem.email = ["aki@jetthoughts.com"]
7
+ gem.description = "It's a small ruby gem for showing popup with images from selected url"
8
+ gem.summary = "It's a small ruby gem for showing popup with images from selected url"
9
+ gem.homepage = "https://github.com/spy-a/images_fetcher"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "images_fetcher"
15
+ gem.require_paths = ["lib", "app"]
16
+ gem.version = ImagesFetcher::VERSION
17
+
18
+ gem.add_dependency 'jquery-rails'
19
+ gem.add_dependency 'jquery-ui-rails'
20
+ gem.add_dependency "bootstrap-sass", ">= 2.0.1"
21
+ gem.add_dependency 'haml'
22
+ end
@@ -0,0 +1,15 @@
1
+ require "images_fetcher/version"
2
+ module ImagesFetcher
3
+
4
+ class Railtie < Rails::Railtie
5
+ initializer "images_fetcher.images_fetcher_helper" do
6
+ ActionView::Base.send :include, ImagesFetcherHelper
7
+ end
8
+ end
9
+
10
+ class Engine < ::Rails::Engine
11
+
12
+ isolate_namespace ImagesFetcher
13
+
14
+ end
15
+ end
@@ -0,0 +1,3 @@
1
+ module ImagesFetcher
2
+ VERSION = "1.0.0"
3
+ end
metadata ADDED
@@ -0,0 +1,125 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: images_fetcher
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Alexey Kisel
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-08-06 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jquery-rails
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: jquery-ui-rails
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: bootstrap-sass
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: 2.0.1
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: 2.0.1
62
+ - !ruby/object:Gem::Dependency
63
+ name: haml
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ description: It's a small ruby gem for showing popup with images from selected url
79
+ email:
80
+ - aki@jetthoughts.com
81
+ executables: []
82
+ extensions: []
83
+ extra_rdoc_files: []
84
+ files:
85
+ - .gitignore
86
+ - Gemfile
87
+ - LICENSE
88
+ - README.md
89
+ - Rakefile
90
+ - app/assets/javascripts/images_fetcher.js.coffee
91
+ - app/assets/stylesheets/images_fetcher.css.scss
92
+ - app/controllers/requests_controller.rb
93
+ - app/helpers/images_fetcher_helper.rb
94
+ - app/views/shared/_choose_image.html.haml
95
+ - app/views/shared/_js.html.haml
96
+ - config/routes.rb
97
+ - images_fetcher.gemspec
98
+ - lib/images_fetcher.rb
99
+ - lib/images_fetcher/version.rb
100
+ homepage: https://github.com/spy-a/images_fetcher
101
+ licenses: []
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ - app
107
+ required_ruby_version: !ruby/object:Gem::Requirement
108
+ none: false
109
+ requirements:
110
+ - - ! '>='
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ required_rubygems_version: !ruby/object:Gem::Requirement
114
+ none: false
115
+ requirements:
116
+ - - ! '>='
117
+ - !ruby/object:Gem::Version
118
+ version: '0'
119
+ requirements: []
120
+ rubyforge_project:
121
+ rubygems_version: 1.8.24
122
+ signing_key:
123
+ specification_version: 3
124
+ summary: It's a small ruby gem for showing popup with images from selected url
125
+ test_files: []