html-pipeline-flickr 0.1.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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: d5734d258824cb3cd4af037ec1029f5bb7c37dc8
4
+ data.tar.gz: 3b532577d2c426c1023ffbe75f2fa00049057736
5
+ SHA512:
6
+ metadata.gz: 1839901d6a252265de0ba94f9b5ef73632b0f247c746030bd7b1405af64ffe40a4cfc7dc4c1a4338af0aa993d19afb13a540b0bf7d2ba515b24c46b1336b3a5a
7
+ data.tar.gz: 3e5496e2323314c2c9d4a7ca0309c00e78f0a0380d565bfe7acbd19a45282def118b6df94e65ba7dc3ac0fa5b1c4b16dec1b2461a59c42e4b239a90e2a56c721
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,15 @@
1
+ language: ruby
2
+
3
+ script: "bundle exec rspec"
4
+ rvm:
5
+ - 2.0
6
+ - 2.1
7
+ - 2.2
8
+ - ruby-head
9
+
10
+ notifications:
11
+ email:
12
+ recipients:
13
+ - stan001212@gmail.com
14
+ on_failure: change
15
+ on_success: never
data/Gemfile ADDED
@@ -0,0 +1,7 @@
1
+ source 'https://rubygems.org'
2
+
3
+ group :test do
4
+ gem "guard-rspec"
5
+ gem "guard"
6
+ end
7
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,11 @@
1
+ guard 'rspec', cmd: "bundle exec rspec" do
2
+ # watch /lib/ files
3
+ watch(%r{^lib/(.+).rb$}) do |m|
4
+ "spec/#{m[1]}_spec.rb"
5
+ end
6
+
7
+ # watch /spec/ files
8
+ watch(%r{^spec/(.+).rb$}) do |m|
9
+ "spec/#{m[1]}.rb"
10
+ end
11
+ end
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ [![Build Status](https://travis-ci.org/st0012/html-pipeline-flickr.svg?branch=master)](https://travis-ci.org/st0012/html-pipeline-flickr)
2
+
3
+ # HTML::Pipeline Flickr Gem
4
+ A html-pipeline filter that converts flickr url into a linkable image
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'html-pipeline'
12
+ gem 'html-pipeline-flickr'
13
+ ```
14
+
15
+ And then execute:
16
+
17
+ $ bundle
18
+
19
+ Or install it yourself as:
20
+
21
+ $ gem install html-pipeline-flickr
22
+
23
+ ## Usage
24
+
25
+ See [html-pipeline](https://github.com/jch/html-pipeline)
26
+
27
+
28
+ ## Development
29
+
30
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/console` for an interactive prompt that will allow you to experiment.
31
+
32
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release` to create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
33
+
34
+ ## Contributing
35
+
36
+ 1. [Fork it]( https://github.com/st0012/html-pipeline-flickr/fork )
37
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
38
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
39
+ 4. Push to the branch (`git push origin my-new-feature`)
40
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "html/pipeline/flickr"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,7 @@
1
+ #!/bin/bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+
5
+ bundle install
6
+
7
+ # Do any other automated setup that you need to do here
@@ -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 'html/pipeline/flickr/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "html-pipeline-flickr"
8
+ spec.version = HTML::Pipeline::Flickr::VERSION
9
+ spec.authors = ["Stan Luo"]
10
+ spec.email = ["stan001212@gmail.com"]
11
+
12
+ spec.summary = %q{Flickr filter for html-pipeline}
13
+ spec.description = %q{A html-pipeline filter that converts flickr url into a linkable image}
14
+ spec.homepage = "https://github.com/st0012/html-pipeline-flickr"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = "exe"
18
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "html-pipeline", "~> 2.0"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ end
@@ -0,0 +1,10 @@
1
+ require "html/pipeline/flickr/version"
2
+ require "html/pipeline/flickr/flickr_filter"
3
+
4
+ module HTML
5
+ class Pipeline
6
+ module Flickr
7
+ # Your code goes here...
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,45 @@
1
+ require 'html/pipeline'
2
+ require 'uri'
3
+ require 'net/http'
4
+ require 'json'
5
+
6
+ module HTML
7
+ class Pipeline
8
+ # HTML Filter for converting flickr's link into linkable image
9
+ #
10
+ # Context options:
11
+ # :flickr_maxwidth, flickr_minheight - representing maxwidth and maxheight in oembed format's params.
12
+ # :flickr_link_attr - HTML attributes for the link that will be generated
13
+
14
+ class FlickrFilter < TextFilter
15
+ def call
16
+ regex = %r{https?://(www\.)?flickr\.com/photos/[^\s<]*}
17
+ uri = URI("https://www.flickr.com/services/oembed")
18
+
19
+ link_attr = context[:flickr_link_attr] || ""
20
+
21
+ @text.gsub(regex) do |match|
22
+ params = {
23
+ url: match,
24
+ format: :json,
25
+ maxwidth: max_value(:width),
26
+ maxheight: max_value(:height)
27
+ }
28
+
29
+ uri.query = URI.encode_www_form(params)
30
+
31
+ response = JSON.parse(Net::HTTP.get(uri))
32
+
33
+ %{<a href="#{match}" #{link_attr}><img src="#{response["url"]}" alt="#{response["title"]}" title="#{response["title"]}" /></a>}
34
+ end
35
+ end
36
+
37
+ private
38
+
39
+ def max_value(attr)
40
+ value = context["flickr_max#{attr}".to_sym]
41
+ value.to_i >= 0 ? value.to_i : 0
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ module HTML
2
+ class Pipeline
3
+ module Flickr
4
+ VERSION = "0.1.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: html-pipeline-flickr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Stan Luo
8
+ autorequire:
9
+ bindir: exe
10
+ cert_chain: []
11
+ date: 2015-07-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: html-pipeline
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '2.0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '2.0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: A html-pipeline filter that converts flickr url into a linkable image
42
+ email:
43
+ - stan001212@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".rspec"
50
+ - ".travis.yml"
51
+ - Gemfile
52
+ - Guardfile
53
+ - README.md
54
+ - Rakefile
55
+ - bin/console
56
+ - bin/setup
57
+ - html-pipeline-flickr.gemspec
58
+ - lib/html/pipeline/flickr.rb
59
+ - lib/html/pipeline/flickr/flickr_filter.rb
60
+ - lib/html/pipeline/flickr/version.rb
61
+ homepage: https://github.com/st0012/html-pipeline-flickr
62
+ licenses: []
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.5
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Flickr filter for html-pipeline
84
+ test_files: []
85
+ has_rdoc: