middleman-galley 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 10752cd763741094cdbd6a501e81d2ce44e7fb6f
4
- data.tar.gz: 728e6ab302b4b9d457298ab3d65a9b2763ff3fce
3
+ metadata.gz: bc0d801d89dc81d43ba264f054f246a6290ba7f6
4
+ data.tar.gz: 25fc2db28a67d225b54c1dfc458cf1cf6e4fa80f
5
5
  SHA512:
6
- metadata.gz: aefcb04fb033bac2a95047eaf4d0877ef04a6e1f839cd368c2bbb65a4e0f322c7cca653fc43aec397532040d8b989a689d36e2c2332f9c7dbb0effab1734641b
7
- data.tar.gz: 85208cee122766098e57c876a2b71b21ffe80d74b9b01854c600b1ae61f34fa25502630562d4f2a5a04484066909bac3ea33a45b0c8c02fed84923754b050223
6
+ metadata.gz: e048802b007b94abdf19a5c7d4179e455409396e0cb1d026c6236230e32c91810bc81280b2146f5b3a775008d07428ceaf2b7c88eadc625550ece835b88df839
7
+ data.tar.gz: 438544e8d0756e561e0cfae667018cbe98defaff921ce4c20968ac2471bf811b3e612d1d9dfa07974e86151c51551e135eb87da473e9c763eabeaace063ca495
@@ -0,0 +1,63 @@
1
+ Feature: Specify view
2
+ In order to have fun
3
+ As a human
4
+ I want to select another view for gallery
5
+
6
+ Background: * basic setup *
7
+ Given I successfully run `middleman init my-site`
8
+ And I cd to "my-site"
9
+
10
+ # images for the gallery
11
+ And I put in my images:
12
+ | source/gallery/cards/one/01.png |
13
+ | source/gallery/cards/one/02.png |
14
+ | source/gallery/cards/two/a1.png |
15
+ | source/gallery/cards/two/a2.png |
16
+ | source/gallery/other/01.png |
17
+ | source/gallery/other/02.png |
18
+
19
+ And I append to "Gemfile" with:
20
+ """
21
+
22
+ gem 'middleman-galley'
23
+ """
24
+ And I successfully run `bundle`
25
+
26
+ And I append to "config.rb" with:
27
+ """
28
+
29
+ set :relative_links, true
30
+ """
31
+
32
+ Scenario: * use default template *
33
+ When I append to "config.rb" with:
34
+ """
35
+
36
+ activate :galley
37
+ """
38
+ And I successfully run `middleman build --verbose`
39
+
40
+ Then document "build/gallery/other/index.html" has 2 ".fotorama > img"
41
+ Then document "build/gallery/other/index.html" has 0 ".Collage > img"
42
+
43
+ Scenario: * set collage view *
44
+ When I append to "config.rb" with:
45
+ """
46
+
47
+ activate :galley, view: :collage
48
+ """
49
+ And I successfully run `middleman build --verbose`
50
+
51
+ Then document "build/gallery/other/index.html" has 0 ".fotorama > img"
52
+ Then document "build/gallery/other/index.html" has 2 ".Collage > img"
53
+
54
+ Scenario: * set fotorama view (it is default anyway) *
55
+ When I append to "config.rb" with:
56
+ """
57
+
58
+ activate :galley, view: :fotorama
59
+ """
60
+ And I successfully run `middleman build --verbose`
61
+
62
+ Then document "build/gallery/other/index.html" has 2 ".fotorama > img"
63
+ Then document "build/gallery/other/index.html" has 0 ".Collage > img"
@@ -0,0 +1,21 @@
1
+ require 'chunky_png'
2
+ require 'pathname'
3
+
4
+ def random_image
5
+ w, h = 2.times.map { rand 100..200 }
6
+ color = ChunkyPNG::Color.rgb *3.times.map { rand 0..255 }
7
+ ChunkyPNG::Image.new w, h, color
8
+ end
9
+
10
+ And 'I put in my images:' do |table|
11
+ files = table.raw.map &:first
12
+ files.each { |file|
13
+ in_current_dir {
14
+ dir = Pathname(file).parent
15
+ dir.mkpath unless dir.exist?
16
+ random_image.save file, :fast_rgba
17
+ }
18
+ #file = file[0]
19
+ #step "an empty file named \"#{file}\""
20
+ }
21
+ end
@@ -1,12 +1,12 @@
1
1
  require 'nokogiri'
2
2
 
3
- Given 'I prepare following files:' do |table|
4
- files = table.raw
5
- files.each { |file|
6
- file = file[0]
7
- step "an empty file named \"#{file}\""
8
- }
9
- end
3
+ #Given 'I prepare following files:' do |table|
4
+ # files = table.raw
5
+ # files.each { |file|
6
+ # file = file[0]
7
+ # step "an empty file named \"#{file}\""
8
+ # }
9
+ #end
10
10
 
11
11
  And /^the file "(.*?)" has links:$/ do |file, table|
12
12
  names, links = table.raw.transpose
@@ -1,4 +1,4 @@
1
- require 'aruba/cucumber'
2
-
3
1
  require 'coveralls'
4
2
  Coveralls.wear!
3
+
4
+ require 'aruba/cucumber'
@@ -1,4 +1,4 @@
1
- Feature: Usage
1
+ Feature: Basic usage
2
2
  In order to have fun
3
3
  As a human
4
4
  I want my images in the browser
@@ -16,7 +16,7 @@ Feature: Usage
16
16
  And I cd to "my-site"
17
17
 
18
18
  # images for the gallery
19
- And I prepare following files:
19
+ And I put in my images:
20
20
  | source/gallery/cards/one/01.png |
21
21
  | source/gallery/cards/one/02.png |
22
22
  | source/gallery/cards/two/a1.png |
@@ -19,7 +19,7 @@ module Middleman
19
19
  class Ext < Extension
20
20
  extend GemStuff
21
21
 
22
- self.option :default_template, 'fotorama',
22
+ self.option :view, 'fotorama',
23
23
  'default gallery template'
24
24
 
25
25
  self.option :at, 'gallery',
@@ -40,6 +40,7 @@ module Middleman
40
40
 
41
41
  def initialize app, options_hash={}, &block
42
42
  app.send :include, Galley::Method
43
+ # kinda explicitness
43
44
 
44
45
  super
45
46
 
@@ -58,7 +59,8 @@ module Middleman
58
59
 
59
60
  helpers do
60
61
  def galley
61
- ::Middleman::Galley::Helper.new self
62
+ Galley::Helper.new self
63
+ # kinda explicitness
62
64
  end
63
65
  end
64
66
 
@@ -1,7 +1,7 @@
1
- require 'middleman/galley/gallery_template'
1
+ require 'middleman/galley/templates'
2
+
3
+ module Middleman::Galley
2
4
 
3
- module Middleman
4
- module Galley
5
5
  class Helper
6
6
  def initialize context
7
7
  @a = context
@@ -20,9 +20,9 @@ module Middleman
20
20
  def images gallery_template = :default
21
21
  if gallery_template == :default
22
22
  gallery_template = a.galley!
23
- .options.default_template
23
+ .options.view
24
24
  end
25
- GalleryTemplate[gallery_template].build a
25
+ Template[gallery_template].build a
26
26
  end
27
27
 
28
28
  private
@@ -43,5 +43,5 @@ module Middleman
43
43
  a.link_to name(res), res
44
44
  end
45
45
  end
46
- end
46
+
47
47
  end
@@ -1,6 +1,9 @@
1
- module Middleman
2
- module Galley
3
- class GalleryTemplate
1
+ require 'forwardable'
2
+ require 'fastimage'
3
+
4
+ module Middleman::Galley
5
+
6
+ class Template
4
7
  @@known = {}
5
8
  def self.[] name
6
9
  name = name.to_sym
@@ -21,7 +24,9 @@ module Middleman
21
24
  end
22
25
 
23
26
  private
24
- def a
27
+ delegate :content_tag, to: :a
28
+
29
+ def a # rid?
25
30
  @context
26
31
  end
27
32
 
@@ -40,7 +45,8 @@ module Middleman
40
45
  else
41
46
  res.url
42
47
  end
43
- a.tag :img, src: url
48
+ w, h = FastImage.size res.source_file
49
+ a.tag :img, src: url, width: w, height: h
44
50
  end
45
51
 
46
52
  IMG = /\.(png|jpg|jpeg|gif|svg|bmp)$/
@@ -52,27 +58,4 @@ module Middleman
52
58
  url.sub a.current_page.url, ''
53
59
  end
54
60
  end
55
-
56
- # todo extract:
57
-
58
- class Fotorama < GalleryTemplate
59
- register :fotorama
60
-
61
- def build
62
- a.content_tag(:script, src:
63
- "http://code.jquery.com/jquery-1.10.2.min.js"){''}
64
- a.content_tag(:script, src:
65
- "http://fotorama.s3.amazonaws.com/4.4.6/fotorama.js"){''}
66
- style = a.content_tag(:script) do <<tag
67
- $("head").append("<link rel='stylesheet' href='http://fotorama.s3.amazonaws.com/4.4.6/fotorama.css' />");
68
- tag
69
- end
70
- images = a.content_tag(:div, class: 'fotorama') do
71
- image_tags.join
72
- end
73
-
74
- nil
75
- end
76
- end
77
- end
78
61
  end
@@ -0,0 +1,6 @@
1
+ require_relative 'template'
2
+ require 'pathname'
3
+ here = Pathname(__FILE__).parent
4
+ Pathname.glob(here + 'templates/*.rb').each { |file|
5
+ require_relative file.to_s
6
+ }
@@ -0,0 +1,44 @@
1
+ module Middleman::Galley
2
+ class CollagePlus < Template
3
+ register :collage
4
+ register :collage_plus
5
+
6
+ def build
7
+ content_tag :div, class: 'Collage' do
8
+ image_tags.join
9
+ end
10
+
11
+ content_tag :script, src:
12
+ 'http://code.jquery.com/jquery-latest.min.js' do
13
+ nil
14
+ end
15
+
16
+ content_tag(:script) { JS }
17
+
18
+ content_tag :script do
19
+ " $('.Collage').collagePlus();"
20
+ end
21
+
22
+ nil # just in case
23
+ end
24
+
25
+ # todo: extract
26
+ JS = <<js
27
+ /*!
28
+ *
29
+ * jQuery collagePlus Plugin v0.3.2
30
+ * https://github.com/ed-lea/jquery-collagePlus
31
+ *
32
+ * Copyright 2012, Ed Lea twitter.com/ed_lea
33
+ *
34
+ * built for http://qiip.me
35
+ *
36
+ * Dual licensed under the MIT or GPL Version 2 licenses.
37
+ * http://www.opensource.org/licenses/mit-license.php
38
+ * http://www.opensource.org/licenses/GPL-2.0
39
+ *
40
+ */
41
+ ;(function(e){e.fn.collagePlus=function(t){function i(t,n,r,i){var o=r.padding*(t.length-1)+t.length*t[0][3],u=r.albumWidth-o,a=u/(n-o),f=o,l=n<r.albumWidth?true:false;for(var c=0;c<t.length;c++){var h=e(t[c][0]),p=Math.floor(t[c][1]*a),d=Math.floor(t[c][2]*a),v=!!(c<t.length-1);if(r.allowPartialLastRow===true&&l===true){p=t[c][1];d=t[c][2]}f+=p;if(!v&&f<r.albumWidth){if(r.allowPartialLastRow===true&&l===true){p=p}else{p=p+(r.albumWidth-f)}}var m=h.is("img")?h:h.find("img");m.width(p);if(!h.is("img")){h.width(p+t[c][3])}m.height(d);if(!h.is("img")){h.height(d+t[c][4])}s(h,v,r);m.load(function(e){return function(){if(r.effect=="default"){e.animate({opacity:"1"},{duration:r.fadeSpeed})}else{if(r.direction=="vertical"){var t=i<=10?i:10}else{var t=c<=9?c+1:10}e.addClass(r.effect);e.addClass("effect-duration-"+t)}}}(h)).each(function(){if(this.complete)e(this).trigger("load")})}}function s(e,t,n){var r={"margin-bottom":n.padding+"px","margin-right":t?n.padding+"px":"0px",display:n.display,"vertical-align":"bottom",overflow:"hidden"};return e.css(r)}function o(t){$img=e(t);var n=new Array;n["w"]=parseFloat($img.css("border-left-width"))+parseFloat($img.css("border-right-width"));n["h"]=parseFloat($img.css("border-top-width"))+parseFloat($img.css("border-bottom-width"));return n}var n={targetHeight:400,albumWidth:this.width(),padding:parseFloat(this.css("padding-left")),images:this.children(),fadeSpeed:"fast",display:"inline-block",effect:"default",direction:"vertical",allowPartialLastRow:false};var r=e.extend({},n,t);return this.each(function(){var t=0,n=[],s=1;r.images.each(function(u){var a=e(this),f=a.is("img")?a:e(this).find("img");var l=typeof f.data("width")!="undefined"?f.data("width"):f.width(),c=typeof f.data("height")!="undefined"?f.data("height"):f.height();var h=o(f);f.data("width",l);f.data("height",c);var p=Math.ceil(l/c*r.targetHeight),d=Math.ceil(r.targetHeight);n.push([this,p,d,h["w"],h["h"]]);t+=p+h["w"]+r.padding;if(t>r.albumWidth&&n.length!=0){i(n,t-r.padding,r,s);delete t;delete n;t=0;n=[];s+=1}if(r.images.length-1==u&&n.length!=0){i(n,t,r,s);delete t;delete n;t=0;n=[];s+=1}})})}})(jQuery);
42
+ js
43
+ end
44
+ end
@@ -0,0 +1,23 @@
1
+ module Middleman::Galley
2
+
3
+ class Fotorama < Template
4
+ register :fotorama
5
+
6
+ def build
7
+ content_tag(:script, src:
8
+ "http://code.jquery.com/jquery-1.10.2.min.js"){''}
9
+ content_tag(:script, src:
10
+ "http://fotorama.s3.amazonaws.com/4.4.6/fotorama.js"){''}
11
+ content_tag(:script) do <<tag
12
+ $("head").append("<link rel='stylesheet' href='http://fotorama.s3.amazonaws.com/4.4.6/fotorama.css' />");
13
+ tag
14
+ end
15
+
16
+ content_tag(:div, class: 'fotorama') do
17
+ image_tags.join
18
+ end
19
+
20
+ nil
21
+ end
22
+ end
23
+ end
@@ -1,5 +1,5 @@
1
1
  module Middleman
2
2
  module Galley
3
- VERSION = "0.0.2"
3
+ VERSION = "0.0.3"
4
4
  end
5
5
  end
@@ -24,7 +24,9 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'aruba'
25
25
  spec.add_development_dependency 'nokogiri'
26
26
  spec.add_development_dependency 'coveralls'
27
+ spec.add_development_dependency 'chunky_png'
27
28
  # moved to Gemfile:
28
29
  #spec.add_development_dependency 'guard-cucumber', group: :guard
29
30
  spec.add_runtime_dependency 'middleman', '~> 3.1'
31
+ spec.add_runtime_dependency 'fastimage'
30
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: middleman-galley
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alexander K
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: chunky_png
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - '>='
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: middleman
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -94,6 +108,20 @@ dependencies:
94
108
  - - ~>
95
109
  - !ruby/object:Gem::Version
96
110
  version: '3.1'
111
+ - !ruby/object:Gem::Dependency
112
+ name: fastimage
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - '>='
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
97
125
  description: 'convenient and simplistic image gallery for middleman '
98
126
  email:
99
127
  - xpyro@ya.ru
@@ -108,13 +136,18 @@ files:
108
136
  - LICENSE.txt
109
137
  - README.md
110
138
  - Rakefile
139
+ - features/change_view.feature
140
+ - features/step_definitions/put_in_my_images_steps.rb
111
141
  - features/step_definitions/usage_steps.rb
112
142
  - features/support/env.rb
113
143
  - features/usage.feature
114
144
  - lib/middleman/galley.rb
115
- - lib/middleman/galley/gallery_template.rb
116
145
  - lib/middleman/galley/gem_stuff.rb
117
146
  - lib/middleman/galley/helper.rb
147
+ - lib/middleman/galley/template.rb
148
+ - lib/middleman/galley/templates.rb
149
+ - lib/middleman/galley/templates/collage_plus.rb
150
+ - lib/middleman/galley/templates/fotorama.rb
118
151
  - lib/middleman/galley/version.rb
119
152
  - middleman-galley.gemspec
120
153
  - templates/index.erb
@@ -143,6 +176,8 @@ signing_key:
143
176
  specification_version: 4
144
177
  summary: image gallery for middleman
145
178
  test_files:
179
+ - features/change_view.feature
180
+ - features/step_definitions/put_in_my_images_steps.rb
146
181
  - features/step_definitions/usage_steps.rb
147
182
  - features/support/env.rb
148
183
  - features/usage.feature