screenshots 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: 35ad4fbb29c8d0e688fe89de3b8dd8e800dc86b6
4
+ data.tar.gz: ba5c15fdd9e24b591bb2a59782def6fed7f6ba38
5
+ SHA512:
6
+ metadata.gz: 839343f6244c729307a99ac1afd1c95d2f1764ec21683248cf188aca8432292f612621ba5187312f959253b4629ed3f5da7b1512f0887873a38b8be01c94facf
7
+ data.tar.gz: 63d007e8db52d1925a3ae6b8740a8902184018b71a931d3355da50579c8dfc0788c654536882d82ddf2155f30113c14bc37732e5083fb91634e2fcd4f5815c5f
data/.gitignore ADDED
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/.ruby-gemset ADDED
@@ -0,0 +1 @@
1
+ screenshots
data/.ruby-version ADDED
@@ -0,0 +1 @@
1
+ ruby-2.1.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in screenshots.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2014 Jean-Baptiste Goulain
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,57 @@
1
+ # Screenshots
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'screenshots'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install screenshots
20
+
21
+ ## Configuration
22
+
23
+ ```ruby
24
+ # config/initializers/screenshots.rb
25
+ Screenshots.configure do |config|
26
+ config.blog_assets_url = 'http://www.codeur.com/blog/wp-content/uploads/2014/07'
27
+ config.image_extension = 'jpg'
28
+ end
29
+ ```
30
+
31
+ ## Usage
32
+
33
+ ### Generate HTML for a single URL
34
+
35
+ ```ruby
36
+ Screenshots::Processor.generate('http://www.google.com')
37
+ ```
38
+
39
+ It returns a string containing the HTML code to be copied in the blog post:
40
+ ```html
41
+ <h2><a href="http://www.google.com">Google</a></h2>
42
+ <img src="http://www.codeur.com/blog/wp-content/uploads/2014/07/http_www.google.com.jpg" />
43
+ ```
44
+
45
+ ### Generate HTML for a list of URLs
46
+
47
+ ```ruby
48
+ Screenshots::Processor.generate_list(['http://www.google.com', 'http://www.lemonde.fr'])
49
+ ```
50
+
51
+ ## Contributing
52
+
53
+ 1. Fork it ( https://github.com/[my-github-username]/screenshots/fork )
54
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
55
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
56
+ 4. Push to the branch (`git push origin my-new-feature`)
57
+ 5. Create a new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
data/bin/screenshots ADDED
@@ -0,0 +1,45 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require 'screenshots'
4
+
5
+ input_file_path = ARGV[0] || ''
6
+ unless File.file?(input_file_path)
7
+ puts "The input file is invalid."
8
+ puts "screenshots my-input-file.txt"
9
+ puts "screenshots my-input-file.txt my/output/folder"
10
+ exit -1
11
+ end
12
+
13
+ output_path = ARGV[1] || Dir.pwd
14
+ unless File.directory?(output_path)
15
+ puts "The output folder is invalid."
16
+ puts "screenshots my-input-file.txt"
17
+ puts "screenshots my-input-file.txt my/output/folder"
18
+ exit -1
19
+ end
20
+
21
+ # Load input file
22
+ urls = []
23
+ File.open(input_file_path, 'r') do |file|
24
+ file.each_line do |line|
25
+ urls << line.chomp if line.start_with?('http')
26
+ end
27
+ end
28
+
29
+ if urls.empty?
30
+ puts "No URL found."
31
+ exit -1
32
+ end
33
+
34
+ # Generate the HTML
35
+ html = Screenshots::Processor.generate_list(urls)
36
+
37
+ # Print output on disk
38
+ output_file = File.join(output_path, 'html_for_blog.txt')
39
+ if File.file?(output_file)
40
+ File.delete(output_file)
41
+ end
42
+
43
+ File.open(output_file, 'w') do |file|
44
+ file.write(html)
45
+ end
@@ -0,0 +1,22 @@
1
+ module Screenshots
2
+ class Configuration
3
+ attr_accessor :blog_assets_url, :image_extension
4
+
5
+ def initialize
6
+ self.blog_assets_url = ''
7
+ self.image_extension = 'jpg'
8
+ end
9
+ end
10
+
11
+ class << self
12
+ attr_accessor :configuration
13
+ end
14
+
15
+ def self.configuration
16
+ @configuration ||= Configuration.new
17
+ end
18
+
19
+ def self.configure
20
+ yield(configuration) if block_given?
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ require 'mechanize'
2
+
3
+ module Screenshots
4
+ class Page
5
+ attr_reader :url, :title, :screenshot_name, :screenshot_url
6
+
7
+ def initialize(url)
8
+ @url = url
9
+ @screenshot_name = generate_screenshot_name(@url)
10
+ @blog_assets_url = Screenshots.configuration.blog_assets_url
11
+ @screenshot_extension = Screenshots.configuration.image_extension
12
+
13
+ agent = Mechanize.new
14
+ agent.get(@url) do |page|
15
+ @title = page.title
16
+ end
17
+ end
18
+
19
+ def generate_blog_section
20
+ section = "<h2><a href=\"#{@url}\">#{@title}</a></h2>\n"
21
+ section += "<img src=\"#{screenshot_url}\" />\n"
22
+ end
23
+
24
+ def screenshot_url
25
+ @screenshot_url ||= File.join(@blog_assets_url, @screenshot_name + "." + @screenshot_extension)
26
+ end
27
+
28
+ private
29
+
30
+ def generate_screenshot_name(url)
31
+ url.gsub(/(\:\/)*\//, '_')
32
+ .gsub(/[\?=\+\\&]/, '_')
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,18 @@
1
+ module Screenshots
2
+ module Processor
3
+
4
+ def self.generate(url)
5
+ page = Screenshots::Page.new(url)
6
+ page.generate_blog_section
7
+ end
8
+
9
+ def self.generate_list(urls)
10
+ html = ""
11
+ urls.each do |url|
12
+ html += generate(url)
13
+ html += "\n"
14
+ end
15
+ html
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,3 @@
1
+ module Screenshots
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,4 @@
1
+ require "screenshots/version"
2
+ require "screenshots/configuration"
3
+ require "screenshots/page"
4
+ require "screenshots/processor"
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'screenshots/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "screenshots"
8
+ spec.version = Screenshots::VERSION
9
+ spec.authors = ["Jean-Baptiste Goulain"]
10
+ spec.email = ["jibai31@gmail.com"]
11
+ spec.summary = %q{Get information on websites to be published in a blog}
12
+ spec.description = %q{Takes a list of URLs, and generates a blog-friendly code that presents each of the websites}
13
+ spec.homepage = ""
14
+ spec.license = "MIT"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0")
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.6"
22
+ spec.add_development_dependency "rake", "~> 10.0"
23
+ spec.add_development_dependency "rspec"
24
+
25
+ spec.add_runtime_dependency "mechanize", '~> 2.7'
26
+ end
@@ -0,0 +1,12 @@
1
+ require 'spec_helper'
2
+
3
+ describe Screenshots::Configuration do
4
+
5
+ it "has a root_url" do
6
+ expect(Screenshots.configuration.blog_assets_url).to eq('http://blog')
7
+ end
8
+
9
+ it "has an image_extension" do
10
+ expect(Screenshots.configuration.image_extension).to eq('jpg')
11
+ end
12
+ end
@@ -0,0 +1,40 @@
1
+ require 'spec_helper'
2
+
3
+ describe Screenshots::Page do
4
+ before(:all) do
5
+ @url = 'https://github.com/rails/rails?param=1&x=2'
6
+ @page = Screenshots::Page.new(@url)
7
+ end
8
+
9
+ describe "#url" do
10
+ it "returns the URL" do
11
+ expect(@page.url).to eq(@url)
12
+ end
13
+ end
14
+
15
+ describe "#title" do
16
+ it "returns the page meta title" do
17
+ expect(@page.title).to eq('rails/rails · GitHub')
18
+ end
19
+ end
20
+
21
+ describe "#screenshot_name" do
22
+ it "is generated from the url" do
23
+ expect(@page.screenshot_name).to eq('https_github.com_rails_rails_param_1_x_2')
24
+ end
25
+ end
26
+
27
+ describe "#screenshot_url" do
28
+ it "returns the full url of the screenshot on the blog" do
29
+ expect(@page.screenshot_url).to eq('http://blog/https_github.com_rails_rails_param_1_x_2.jpg')
30
+ end
31
+ end
32
+
33
+ describe "#generate_blog_section" do
34
+ it "generates HTML code with a title and a picture" do
35
+
36
+ output = TestData.github_html_section
37
+ expect(@page.generate_blog_section).to eq(output)
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ require 'spec_helper'
2
+
3
+ describe Screenshots::Processor do
4
+
5
+ describe ".generate" do
6
+ it "generates an HTML section for one site" do
7
+ url = 'http://www.google.com'
8
+ html = Screenshots::Processor.generate(url)
9
+ expect(html).to eq(TestData.google_html_section)
10
+ end
11
+ end
12
+
13
+ describe ".generate_list" do
14
+ it "generates HTML sections for a list of sites" do
15
+ urls = [
16
+ 'http://www.google.com',
17
+ 'https://github.com/rails/rails?param=1&x=2'
18
+ ]
19
+
20
+ expected_output = TestData.google_html_section + "\n" + TestData.github_html_section + "\n"
21
+
22
+ html = Screenshots::Processor.generate_list(urls)
23
+ expect(html).to eq(expected_output)
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+
3
+ require 'screenshots'
4
+ require 'test_data'
5
+
6
+ include TestData
7
+
8
+ Screenshots.configure do |config|
9
+ config.blog_assets_url = 'http://blog'
10
+ end
data/spec/test_data.rb ADDED
@@ -0,0 +1,14 @@
1
+ module TestData
2
+
3
+ def github_html_section
4
+ %Q(<h2><a href="https://github.com/rails/rails?param=1&x=2">rails/rails · GitHub</a></h2>
5
+ <img src="http://blog/https_github.com_rails_rails_param_1_x_2.jpg" />
6
+ )
7
+ end
8
+
9
+ def google_html_section
10
+ %Q(<h2><a href="http://www.google.com">Google</a></h2>
11
+ <img src="http://blog/http_www.google.com.jpg" />
12
+ )
13
+ end
14
+ end
metadata ADDED
@@ -0,0 +1,127 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: screenshots
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Jean-Baptiste Goulain
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-07-23 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.6'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.6'
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
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: mechanize
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '2.7'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '2.7'
69
+ description: Takes a list of URLs, and generates a blog-friendly code that presents
70
+ each of the websites
71
+ email:
72
+ - jibai31@gmail.com
73
+ executables:
74
+ - screenshots
75
+ extensions: []
76
+ extra_rdoc_files: []
77
+ files:
78
+ - ".gitignore"
79
+ - ".rspec"
80
+ - ".ruby-gemset"
81
+ - ".ruby-version"
82
+ - Gemfile
83
+ - LICENSE.txt
84
+ - README.md
85
+ - Rakefile
86
+ - bin/screenshots
87
+ - lib/screenshots.rb
88
+ - lib/screenshots/configuration.rb
89
+ - lib/screenshots/page.rb
90
+ - lib/screenshots/processor.rb
91
+ - lib/screenshots/version.rb
92
+ - screenshots.gemspec
93
+ - spec/screenshots/configuration_spec.rb
94
+ - spec/screenshots/page_spec.rb
95
+ - spec/screenshots/processor_spec.rb
96
+ - spec/spec_helper.rb
97
+ - spec/test_data.rb
98
+ homepage: ''
99
+ licenses:
100
+ - MIT
101
+ metadata: {}
102
+ post_install_message:
103
+ rdoc_options: []
104
+ require_paths:
105
+ - lib
106
+ required_ruby_version: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ required_rubygems_version: !ruby/object:Gem::Requirement
112
+ requirements:
113
+ - - ">="
114
+ - !ruby/object:Gem::Version
115
+ version: '0'
116
+ requirements: []
117
+ rubyforge_project:
118
+ rubygems_version: 2.4.1
119
+ signing_key:
120
+ specification_version: 4
121
+ summary: Get information on websites to be published in a blog
122
+ test_files:
123
+ - spec/screenshots/configuration_spec.rb
124
+ - spec/screenshots/page_spec.rb
125
+ - spec/screenshots/processor_spec.rb
126
+ - spec/spec_helper.rb
127
+ - spec/test_data.rb