dropsite 0.2.1 → 0.3.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/Rakefile +12 -3
- data/bin/dropsite +1 -34
- data/dropsite.gemspec +1 -1
- data/lib/dropsite/application.rb +93 -0
- data/lib/dropsite/dir_renderer.rb +23 -25
- data/lib/dropsite/plugins/image_thumbnails/assets/css/image_thumbnails.css +87 -0
- data/lib/dropsite/plugins/image_thumbnails/assets/css/reset.css +30 -0
- data/lib/dropsite/plugins/image_thumbnails/assets/images/icons/directory-large.png +0 -0
- data/lib/dropsite/plugins/image_thumbnails/assets/images/icons/directory.png +0 -0
- data/lib/dropsite/plugins/image_thumbnails/assets/images/row-bg.png +0 -0
- data/lib/dropsite/plugins/image_thumbnails/image_thumbnails.erb +49 -0
- data/lib/dropsite/plugins/image_thumbnails/image_thumbnails.rb +65 -0
- data/lib/dropsite/plugins/simple_index/simple_index.erb +1 -1
- data/lib/dropsite/plugins/simple_index/simple_index.rb +1 -1
- data/lib/dropsite/render_helper.rb +60 -22
- data/lib/dropsite/site.rb +30 -28
- data/lib/dropsite/site_dir.rb +84 -32
- data/lib/dropsite/site_file.rb +12 -11
- data/lib/dropsite.rb +34 -9
- data/test/fixtures/many_folders_public/one/two/three/four/five/six/seven/eight/file.txt +1 -0
- data/test/helper.rb +17 -4
- data/test/{test_write_site.rb → integration/test_process_site.rb} +31 -44
- data/test/integration/test_process_site_many_folders.rb +18 -0
- data/test/integration/test_process_site_with_thumbnails.rb +40 -0
- data/test/unit/test_application.rb +19 -0
- data/test/unit/test_config_file.rb +34 -0
- data/test/{test_render_helper.rb → unit/test_render_helper.rb} +13 -13
- data/test/{test_site.rb → unit/test_site.rb} +19 -3
- data/test/unit/test_site_dir.rb +31 -0
- data/test/{test_site_file.rb → unit/test_site_file.rb} +9 -9
- metadata +27 -19
- data/lib/dropsite/plugins/simple_index/assets/simple_index.js +0 -3
- data/test/test_site_dir.rb +0 -20
data/lib/dropsite/site.rb
CHANGED
@@ -1,35 +1,34 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
|
3
3
|
module Dropsite
|
4
|
-
VERSION = '0.2'
|
5
|
-
|
6
4
|
# Main site builder class. Some inspiration here from Jekyll (github.com/mojombo/jekyll).
|
7
5
|
class Site
|
8
|
-
attr_reader :site_tree, :public_dir
|
9
|
-
|
6
|
+
attr_reader :site_tree, :public_dir, :exclude, :disabled_plugins, :site_files_dir
|
7
|
+
|
10
8
|
def initialize(config)
|
11
9
|
if config.is_a? String
|
12
10
|
@public_dir = config
|
13
|
-
@
|
11
|
+
@exclude, @disabled_plugins = [], []
|
14
12
|
@quiet = false
|
15
13
|
else
|
16
14
|
@config = config.clone
|
17
15
|
@public_dir = config[:public_dir]
|
18
|
-
@
|
16
|
+
@exclude = config[:exclude] || []
|
17
|
+
@disabled_plugins = config[:disabled_plugins] || []
|
19
18
|
@quiet = config[:quiet] || false
|
20
19
|
end
|
21
|
-
|
20
|
+
|
22
21
|
@site_tree = nil
|
23
22
|
@site_files_dir = File.join(@public_dir, 'dropsite')
|
24
23
|
end
|
25
|
-
|
24
|
+
|
26
25
|
def process
|
27
26
|
clean
|
28
27
|
read
|
29
28
|
render
|
30
29
|
write
|
31
30
|
end
|
32
|
-
|
31
|
+
|
33
32
|
# Cleans up files previously generated by Dropsite (or at least ones)
|
34
33
|
# that look like they are. By default this will be an index.html
|
35
34
|
# file and dropsite directory in the Public directory root.
|
@@ -38,49 +37,52 @@ module Dropsite
|
|
38
37
|
notice "Deleting existing site files dir at #{@site_files_dir}"
|
39
38
|
FileUtils.rm_rf(@site_files_dir)
|
40
39
|
end
|
41
|
-
|
40
|
+
|
42
41
|
index_file = File.join(@public_dir, 'index.html')
|
43
42
|
if File.exist?(index_file)
|
44
43
|
notice "Deleting existing top-level index at #{index_file}"
|
45
44
|
File.delete(index_file)
|
46
45
|
end
|
47
46
|
end
|
48
|
-
|
47
|
+
|
49
48
|
def read
|
50
49
|
@site_tree = read_directory
|
51
50
|
end
|
52
|
-
|
51
|
+
|
53
52
|
def render
|
54
|
-
|
53
|
+
site_tree.render
|
55
54
|
end
|
56
|
-
|
55
|
+
|
57
56
|
def write
|
58
|
-
notice "Creating site files dir at #{
|
59
|
-
Dir.mkdir(
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
Dir.mkdir(site_assets_dir)
|
57
|
+
notice "Creating site files dir at #{site_files_dir}"
|
58
|
+
Dir.mkdir(site_files_dir)
|
59
|
+
site_tree.write
|
60
|
+
|
61
|
+
Dir.mkdir(assets_dir)
|
64
62
|
DirRenderer.renderers.each do |r|
|
65
63
|
if File.exist? r.assets_dir
|
66
|
-
FileUtils.cp_r(r.assets_dir, File.join(
|
64
|
+
FileUtils.cp_r(r.assets_dir, File.join(assets_dir, Dropsite.underscorize(r.class.to_s)))
|
67
65
|
end
|
68
66
|
end
|
69
67
|
end
|
70
|
-
|
68
|
+
|
69
|
+
def assets_dir
|
70
|
+
File.join(@site_files_dir, 'dropsite-assets')
|
71
|
+
end
|
72
|
+
|
71
73
|
def notice(message)
|
72
74
|
return if @quiet
|
73
75
|
warn "#{File.basename($0)}: #{message}"
|
74
76
|
end
|
75
|
-
|
77
|
+
|
76
78
|
protected
|
77
|
-
|
79
|
+
|
78
80
|
def read_directory(dir='')
|
79
81
|
base = File.join(@public_dir, dir)
|
80
82
|
entries = filter_entries(Dir.entries(base))
|
81
|
-
|
83
|
+
|
82
84
|
dir_entries = []
|
83
|
-
|
85
|
+
|
84
86
|
entries.each do |f|
|
85
87
|
f_abs = File.join(base, f)
|
86
88
|
f_rel = File.join(dir, f).sub(/^\//, '')
|
@@ -96,10 +98,10 @@ module Dropsite
|
|
96
98
|
end
|
97
99
|
SiteDir.new(dir, dir_entries, self)
|
98
100
|
end
|
99
|
-
|
101
|
+
|
100
102
|
def filter_entries(entries)
|
101
103
|
entries.reject do |e|
|
102
|
-
['.', '_', '#'].include?(e[0..0]) || e[-1..-1] == '~' || @
|
104
|
+
['.', '_', '#'].include?(e[0..0]) || e[-1..-1] == '~' || @exclude.include?(e)
|
103
105
|
end
|
104
106
|
end
|
105
107
|
end
|
data/lib/dropsite/site_dir.rb
CHANGED
@@ -1,59 +1,111 @@
|
|
1
1
|
module Dropsite
|
2
2
|
class SiteDir < SiteItem
|
3
3
|
attr_accessor :entries
|
4
|
-
|
4
|
+
attr_reader :site, :path, :content
|
5
|
+
|
5
6
|
def initialize(path, entries, site)
|
6
7
|
@path = path == '/' ? '' : path
|
7
8
|
@entries = entries
|
8
9
|
@site = site
|
9
10
|
@content = nil
|
10
11
|
end
|
11
|
-
|
12
|
+
|
12
13
|
def render
|
13
|
-
@content =
|
14
|
+
@content = renderer.render(self)
|
14
15
|
dirs.each {|dir| dir.render}
|
15
16
|
end
|
16
|
-
|
17
|
+
|
18
|
+
# Writes the page for this directory, plus any additional files needed by the page.
|
17
19
|
def write
|
18
20
|
if root?
|
19
|
-
|
20
|
-
index_file = File.join(@site.public_dir, 'index.html')
|
21
|
+
index_file = File.join(page_dir, 'index.html')
|
21
22
|
notice "Writing top level index file at #{index_file}"
|
22
|
-
File.open(index_file, 'w') {|f| f.puts
|
23
|
+
File.open(index_file, 'w') {|f| f.puts content}
|
23
24
|
else
|
24
|
-
#
|
25
|
-
|
26
|
-
|
27
|
-
index_file
|
28
|
-
|
29
|
-
|
30
|
-
Dir.mkdir(
|
25
|
+
# First create the index page
|
26
|
+
index_file = File.join(page_dir, name + '.html')
|
27
|
+
notice "Writing index file for directory #{path} at #{index_file}"
|
28
|
+
File.open(index_file, 'w') {|f| f.puts content}
|
29
|
+
|
30
|
+
# Create a directory to contain index pages for any child directories
|
31
|
+
Dir.mkdir(File.join(page_dir, name))
|
31
32
|
end
|
32
33
|
dirs.sort.each{|dir| dir.write}
|
34
|
+
|
35
|
+
# Determine if the page assets directory is necessary, to avoid clutter
|
36
|
+
writing_page_assets = true
|
37
|
+
begin
|
38
|
+
# Detect whether the write_page_assets method is overridden
|
39
|
+
# In case this explodes in 1.8.6 we'll always create the directory
|
40
|
+
writing_page_assets = renderer.class.instance_method(:write_page_assets).owner != DirRenderer
|
41
|
+
rescue
|
42
|
+
end
|
43
|
+
|
44
|
+
# The renderer knows what assets are linked to and what needs to be available
|
45
|
+
# to display the page properly
|
46
|
+
if writing_page_assets
|
47
|
+
Dir.mkdir(page_assets_dir)
|
48
|
+
renderer.write_page_assets(self)
|
49
|
+
end
|
33
50
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
51
|
+
|
52
|
+
# All regular files in this directory
|
53
|
+
def files; entries.find_all {|e| e.is_a? SiteFile} end
|
54
|
+
|
55
|
+
# All directories in this directory
|
56
|
+
def dirs; entries.find_all {|e| e.is_a? SiteDir} end
|
57
|
+
|
58
|
+
# Is this the site root directory?
|
59
|
+
def root?; path == '' end
|
60
|
+
|
61
|
+
# The file type is always 'directory'
|
62
|
+
def file_type; 'directory' end
|
63
|
+
|
64
|
+
# The human readable size is blank
|
65
|
+
def size; '' end
|
66
|
+
|
67
|
+
# Directory where the page will be written
|
68
|
+
def page_dir
|
69
|
+
if root?
|
70
|
+
site.public_dir
|
71
|
+
else
|
72
|
+
pieces = path.sub(/^\//, '').split('/')
|
73
|
+
File.join(site.site_files_dir, *pieces[0..-2])
|
74
|
+
end
|
37
75
|
end
|
38
|
-
|
39
|
-
|
40
|
-
|
76
|
+
|
77
|
+
# Directory to store extra files needed by the page rendered to represent this directory.
|
78
|
+
# This will almost always be the directory the page is in, except for the case of the
|
79
|
+
# root index page. Since the root index page is in Dropbox/Public and we don't want to
|
80
|
+
# pollute that directory we put the assets in the root of the dropsite directory.
|
81
|
+
def page_assets_dir
|
82
|
+
File.join(root? ? site.site_files_dir : page_dir, page_assets_dir_name)
|
41
83
|
end
|
42
|
-
|
43
|
-
def
|
44
|
-
|
84
|
+
|
85
|
+
def to_s
|
86
|
+
"SiteDir(#{is_root? ? 'root' : path})"
|
45
87
|
end
|
46
|
-
|
47
|
-
|
48
|
-
|
88
|
+
|
89
|
+
protected
|
90
|
+
|
91
|
+
def page_assets_dir_name
|
92
|
+
"dropsite-#{root? ? 'root-index-directory' : name}-assets"
|
49
93
|
end
|
50
|
-
|
51
|
-
|
52
|
-
|
94
|
+
|
95
|
+
# Find the first renderer that can render this SiteDir. Non-built-in (user) plugins
|
96
|
+
# are searched first.
|
97
|
+
def renderer
|
98
|
+
DirRenderer.renderers.partition {|r| !r.built_in?}.flatten.find do |r|
|
99
|
+
r.can_render?(self) && !plugin_disabled?(r)
|
100
|
+
end
|
53
101
|
end
|
54
|
-
|
55
|
-
|
56
|
-
|
102
|
+
|
103
|
+
# Figures out whether the plugin with the given name is disabled. This matches against the
|
104
|
+
# Site's disabled list, ignoring underscores and case.
|
105
|
+
def plugin_disabled?(plugin)
|
106
|
+
site.disabled_plugins.find do |p|
|
107
|
+
p.gsub(/_/, '').downcase == plugin.class.name.gsub(/_/, '').downcase
|
108
|
+
end
|
57
109
|
end
|
58
110
|
end
|
59
111
|
end
|
data/lib/dropsite/site_file.rb
CHANGED
@@ -1,29 +1,30 @@
|
|
1
1
|
module Dropsite
|
2
2
|
class SiteFile < SiteItem
|
3
3
|
EXTENSIONS = {
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
:image => %w[jpg jpeg gif png],
|
5
|
+
:text => %w[txt],
|
6
|
+
:pdf => %w[pdf]
|
7
7
|
}
|
8
|
-
|
9
|
-
attr_accessor :size_in_bytes
|
10
|
-
|
8
|
+
|
9
|
+
attr_accessor :size_in_bytes, :abs_path
|
10
|
+
|
11
11
|
def initialize(rel_path, abs_path=nil, site=nil)
|
12
12
|
@path = rel_path
|
13
|
+
@abs_path = abs_path
|
13
14
|
@size_in_bytes = File.size(abs_path) if abs_path
|
14
15
|
@site = site
|
15
16
|
end
|
16
|
-
|
17
|
+
|
17
18
|
def file_type
|
18
19
|
if File.extname(name).empty?
|
19
|
-
|
20
|
+
:unknown
|
20
21
|
else
|
21
22
|
ext = File.extname(name).sub(/^\./, '')
|
22
23
|
EXTENSIONS.each {|k, v| return k if v.include? ext}
|
23
|
-
return
|
24
|
+
return :unknown
|
24
25
|
end
|
25
26
|
end
|
26
|
-
|
27
|
+
|
27
28
|
# Human readable file size
|
28
29
|
def size
|
29
30
|
return '' if !@size_in_bytes
|
@@ -33,7 +34,7 @@ module Dropsite
|
|
33
34
|
s = "%.1f" % (@size_in_bytes.to_f / 1024 ** e)
|
34
35
|
s.sub(/\.?0*$/, " #{units[e]}")
|
35
36
|
end
|
36
|
-
|
37
|
+
|
37
38
|
def to_s
|
38
39
|
"SiteFile(#{@path})"
|
39
40
|
end
|
data/lib/dropsite.rb
CHANGED
@@ -1,21 +1,46 @@
|
|
1
|
-
|
2
1
|
module Dropsite
|
3
|
-
|
2
|
+
VERSION = '0.2.1'
|
3
|
+
|
4
4
|
# Attempts to find the Dropbox directory (not the Public directory, the Dropbox base
|
5
5
|
# directory) on this box. Returns nil if an existing directory could not be found.
|
6
|
-
def
|
6
|
+
def dropbox_dir
|
7
7
|
return ENV['DROPBOX_HOME'] if ENV['DROPBOX_HOME']
|
8
|
-
|
8
|
+
|
9
9
|
path = case RUBY_PLATFORM
|
10
10
|
when /darwin/, /linux/, /freebsd/
|
11
|
-
File.join(
|
11
|
+
File.join(home_dir, 'Dropbox')
|
12
12
|
when /win32/, /mingw/
|
13
|
-
File.join(
|
13
|
+
File.join(home_dir, 'My Documents', 'My Dropbox')
|
14
14
|
end
|
15
|
-
|
15
|
+
|
16
16
|
File.exist?(path) ? path : nil
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
|
+
# Find the configuration directory for Dropsite. The folder .dropsite is
|
20
|
+
# looked for from most "local" to the Public folder outward. First in the
|
21
|
+
# Public folder, then the Dropsite directory itself (recommended place) and
|
22
|
+
# then the user's home directory.
|
23
|
+
def dropsite_config_dir
|
24
|
+
config_dir_name = '.dropsite'
|
25
|
+
[
|
26
|
+
File.join(dropbox_dir, 'Public', config_dir_name),
|
27
|
+
File.join(dropbox_dir, config_dir_name),
|
28
|
+
File.join(home_dir, config_dir_name)
|
29
|
+
].find {|dir| File.exist? dir}
|
30
|
+
end
|
31
|
+
|
32
|
+
# Platform-specific home directory
|
33
|
+
def home_dir
|
34
|
+
home = ENV['HOME']
|
35
|
+
home = ENV['USERPROFILE'] if not home
|
36
|
+
if !home && (ENV['HOMEDRIVE'] && ENV['HOMEPATH'])
|
37
|
+
home = File.join(ENV['HOMEDRIVE'], ENV['HOMEPATH'])
|
38
|
+
end
|
39
|
+
home = File.expand_path('~') if not home
|
40
|
+
home = 'C:/' if !home && RUBY_PLATFORM =~ /mswin|mingw/
|
41
|
+
home
|
42
|
+
end
|
43
|
+
|
19
44
|
# Convert a camel-cased string into a lowercase, underscore separated string
|
20
45
|
def underscorize(camel_cased_word)
|
21
46
|
camel_cased_word.to_s.gsub(/::/, '/').
|
@@ -25,6 +50,6 @@ module Dropsite
|
|
25
50
|
end
|
26
51
|
end
|
27
52
|
|
28
|
-
%w[dir_renderer render_helper plugins site site_item site_dir site_file].each do |lib|
|
53
|
+
%w[dir_renderer render_helper plugins site site_item site_dir site_file application].each do |lib|
|
29
54
|
require File.join('dropsite', lib)
|
30
55
|
end
|
@@ -0,0 +1 @@
|
|
1
|
+
Contents in the file
|
data/test/helper.rb
CHANGED
@@ -6,9 +6,22 @@ begin
|
|
6
6
|
rescue LoadError
|
7
7
|
end
|
8
8
|
|
9
|
-
|
10
|
-
|
11
|
-
require File.join(FILE_DIR, *%w[.. lib dropsite])
|
9
|
+
require File.join(File.dirname(__FILE__), *%w[.. lib dropsite])
|
12
10
|
include Dropsite
|
13
11
|
|
14
|
-
|
12
|
+
# Fixtures and tmp dir helpers
|
13
|
+
module Fixtures
|
14
|
+
FIXTURES_DIR = File.join(File.dirname(__FILE__), 'fixtures')
|
15
|
+
TMP_DIR = File.join(FIXTURES_DIR, 'tmp')
|
16
|
+
|
17
|
+
def clean_tmp_dir
|
18
|
+
Dir.entries(TMP_DIR).reject {|e| %w[. .. .gitignore].include? e}.each do |entry|
|
19
|
+
file = File.join(TMP_DIR, entry)
|
20
|
+
if File.directory?(file)
|
21
|
+
FileUtils.rm_rf(file)
|
22
|
+
else
|
23
|
+
File.delete(file)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -1,60 +1,60 @@
|
|
1
|
-
require File.join(File.dirname(__FILE__), 'helper')
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
2
2
|
require 'fileutils'
|
3
3
|
require 'nokogiri'
|
4
4
|
|
5
|
-
class
|
6
|
-
|
7
|
-
|
8
|
-
def setup
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
5
|
+
class TestProcessSite < Test::Unit::TestCase
|
6
|
+
include Fixtures
|
7
|
+
|
8
|
+
def setup; clean_tmp_dir end
|
9
|
+
def teardown; clean_tmp_dir end
|
10
|
+
|
11
|
+
def test_process_with_only_simple_index_pages
|
12
|
+
test_public_dir = File.join(TMP_DIR, 'simple_public')
|
13
|
+
FileUtils.cp_r(File.join(FIXTURES_DIR, 'simple_public'), test_public_dir)
|
14
|
+
site = Site.new(
|
15
|
+
:public_dir => test_public_dir,
|
16
|
+
:quiet => true,
|
17
|
+
:disabled_plugins => ['image_thumbnails']
|
18
|
+
)
|
19
19
|
site.process
|
20
|
-
|
20
|
+
|
21
21
|
# Check that all the index pages are there
|
22
|
-
|
22
|
+
|
23
23
|
index_file = File.join(site.public_dir, 'index.html')
|
24
24
|
assert File.exist?(index_file)
|
25
25
|
index_doc = Nokogiri::HTML(IO.read(index_file))
|
26
26
|
assert_equal 3, index_doc.css('.entry').size
|
27
|
-
|
27
|
+
|
28
28
|
assert_equal 'dropsite/pics.html', index_doc.css('a').find {|a| a.content == 'pics'}.attribute('href').value
|
29
|
-
|
29
|
+
|
30
30
|
site_dir = File.join(site.public_dir, 'dropsite')
|
31
31
|
assert File.exist?(site_dir)
|
32
32
|
assert File.directory?(site_dir)
|
33
|
-
|
33
|
+
|
34
34
|
pics_file = File.join(site_dir, 'pics.html')
|
35
35
|
assert File.exist?(pics_file)
|
36
36
|
pics_doc = Nokogiri::HTML(IO.read(pics_file))
|
37
37
|
assert_equal 3, pics_doc.css('.entry').size
|
38
|
-
|
38
|
+
|
39
39
|
# Make sure the the links are correct
|
40
|
-
|
40
|
+
|
41
41
|
['leaves.jpg', 'sculpture.jpg'].each do |pic|
|
42
42
|
assert_equal "../pics/#{pic}", pics_doc.css('a').find {|a| a.content == pic}.attribute('href').value
|
43
43
|
end
|
44
|
-
|
44
|
+
|
45
45
|
assert_equal 'pics/people.html', pics_doc.css('a').find {|a| a.content == 'people'}.attribute('href').value
|
46
|
-
|
46
|
+
|
47
47
|
people_file = File.join(site_dir, 'pics', 'people.html')
|
48
48
|
assert File.exist?(people_file)
|
49
49
|
people_doc = Nokogiri::HTML(IO.read(people_file))
|
50
50
|
assert_equal 2, people_doc.css('.entry').size
|
51
|
-
|
51
|
+
|
52
52
|
['beach.jpg', 'concert.jpg'].each do |pic|
|
53
53
|
assert_equal "../../pics/people/#{pic}", people_doc.css('a').find {|a| a.content == pic}.attribute('href').value
|
54
54
|
end
|
55
|
-
|
55
|
+
|
56
56
|
# Check that the assets were copied in
|
57
|
-
|
57
|
+
|
58
58
|
assets_dir = File.join(site.public_dir, 'dropsite', 'dropsite-assets')
|
59
59
|
assert File.exist?(assets_dir)
|
60
60
|
assert File.directory?(assets_dir)
|
@@ -62,23 +62,23 @@ class TestWriteSite < Test::Unit::TestCase
|
|
62
62
|
assert File.exist?(simple_index_assets_dir)
|
63
63
|
assert File.directory?(simple_index_assets_dir)
|
64
64
|
assert File.exist?(File.join(simple_index_assets_dir, 'css', 'simple_index.css'))
|
65
|
-
|
65
|
+
|
66
66
|
# Check that the assets are included correctly
|
67
|
-
|
67
|
+
|
68
68
|
assert_equal 1, index_doc.css('link').find_all {|l|
|
69
69
|
l.attribute('href').value == 'dropsite/dropsite-assets/simple_index/css/simple_index.css'
|
70
70
|
}.size
|
71
71
|
assert_equal 1, index_doc.css('script').find_all {|l|
|
72
72
|
l.attribute('src').value == 'dropsite/dropsite-assets/simple_index/js/simple_index.js'
|
73
73
|
}.size
|
74
|
-
|
74
|
+
|
75
75
|
assert_equal 1, pics_doc.css('link').find_all {|l|
|
76
76
|
l.attribute('href').value == 'dropsite-assets/simple_index/css/simple_index.css'
|
77
77
|
}.size
|
78
78
|
assert_equal 1, pics_doc.css('script').find_all {|l|
|
79
79
|
l.attribute('src').value == 'dropsite-assets/simple_index/js/simple_index.js'
|
80
80
|
}.size
|
81
|
-
|
81
|
+
|
82
82
|
assert_equal 1, people_doc.css('link').find_all {|l|
|
83
83
|
l.attribute('href').value == '../dropsite-assets/simple_index/css/simple_index.css'
|
84
84
|
}.size
|
@@ -86,17 +86,4 @@ class TestWriteSite < Test::Unit::TestCase
|
|
86
86
|
l.attribute('src').value == '../dropsite-assets/simple_index/js/simple_index.js'
|
87
87
|
}.size
|
88
88
|
end
|
89
|
-
|
90
|
-
protected
|
91
|
-
|
92
|
-
def clean_tmp_dir
|
93
|
-
Dir.entries(TMP_DIR).reject {|e| e =~ /^\./}.each do |entry|
|
94
|
-
file = File.join(TMP_DIR, entry)
|
95
|
-
if File.directory?(file)
|
96
|
-
FileUtils.rm_rf(file)
|
97
|
-
else
|
98
|
-
File.delete(file)
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
89
|
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
2
|
+
require 'fileutils'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class TestProcessSiteManyFolders < Test::Unit::TestCase
|
6
|
+
include Fixtures
|
7
|
+
|
8
|
+
def setup; clean_tmp_dir end
|
9
|
+
|
10
|
+
def test_process_with_many_folders
|
11
|
+
test_public_dir = File.join(TMP_DIR, 'many_folders_public')
|
12
|
+
FileUtils.cp_r(File.join(FIXTURES_DIR, 'many_folders_public'), test_public_dir)
|
13
|
+
site = Site.new(:public_dir => test_public_dir, :quiet => true)
|
14
|
+
site.process
|
15
|
+
|
16
|
+
# TODO: add some tests
|
17
|
+
end
|
18
|
+
end
|
@@ -0,0 +1,40 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
2
|
+
require 'fileutils'
|
3
|
+
require 'nokogiri'
|
4
|
+
|
5
|
+
class TestProcessSiteWithThumbnails < Test::Unit::TestCase
|
6
|
+
include Fixtures
|
7
|
+
|
8
|
+
def setup
|
9
|
+
clean_tmp_dir
|
10
|
+
# Don't use the regular ~/.ruby_inline dir (ImageScience uses RubyInline) and leave
|
11
|
+
# the cached compiled code there, it causes some problems when testing with different
|
12
|
+
# Ruby versions. Delete it after every test.
|
13
|
+
ENV['INLINEDIR'] = File.join(TMP_DIR, 'ruby_inline')
|
14
|
+
Dir.mkdir(ENV['INLINEDIR'])
|
15
|
+
end
|
16
|
+
|
17
|
+
def teardown
|
18
|
+
clean_tmp_dir
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_process_with_image_thumbnails
|
22
|
+
test_public_dir = File.join(TMP_DIR, 'simple_public')
|
23
|
+
FileUtils.cp_r(File.join(FIXTURES_DIR, 'simple_public'), test_public_dir)
|
24
|
+
site = Site.new(
|
25
|
+
:public_dir => test_public_dir,
|
26
|
+
:quiet => true
|
27
|
+
# Don't disable image_thumbnails
|
28
|
+
)
|
29
|
+
site.process
|
30
|
+
|
31
|
+
# Just test the differences from processing with simple index pages, trust
|
32
|
+
# basic Dropsite setup is there
|
33
|
+
|
34
|
+
# TODO: make sure code using both image libraries is tested
|
35
|
+
|
36
|
+
people_thumbs_dir = File.join(test_public_dir, *%w[dropsite pics dropsite-people-assets])
|
37
|
+
assert File.exist?(File.join(people_thumbs_dir, 'beach-thumb.jpg'))
|
38
|
+
assert File.exist?(File.join(people_thumbs_dir, 'concert-thumb.jpg'))
|
39
|
+
end
|
40
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
2
|
+
|
3
|
+
class TestApplication < Test::Unit::TestCase
|
4
|
+
include Fixtures
|
5
|
+
|
6
|
+
def setup; clean_tmp_dir end
|
7
|
+
def teardown; clean_tmp_dir end
|
8
|
+
|
9
|
+
def test_create_config_files
|
10
|
+
ENV['DROPBOX_HOME'] = TMP_DIR
|
11
|
+
ARGV << '-c'
|
12
|
+
Application.new.run
|
13
|
+
|
14
|
+
config_dir = File.join(TMP_DIR, '.dropsite')
|
15
|
+
assert File.directory?(config_dir), 'Config dir created'
|
16
|
+
assert File.file?(File.join(config_dir, 'config.yml')), 'Main config file created'
|
17
|
+
assert File.directory?(File.join(config_dir, 'plugins')), 'plugins dir created'
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'helper')
|
2
|
+
|
3
|
+
class TestConfigFile < Test::Unit::TestCase
|
4
|
+
include Fixtures
|
5
|
+
|
6
|
+
def setup
|
7
|
+
clean_tmp_dir
|
8
|
+
ENV['DROPBOX_HOME'] = TMP_DIR
|
9
|
+
config_dir = File.join(TMP_DIR, '.dropsite')
|
10
|
+
Dir.mkdir(config_dir) if !File.exist?(config_dir)
|
11
|
+
end
|
12
|
+
|
13
|
+
def teardown; clean_tmp_dir end
|
14
|
+
|
15
|
+
def test_read_exclude
|
16
|
+
write_config_file <<-YAML
|
17
|
+
exclude: [ignore_this, and_also_this]
|
18
|
+
YAML
|
19
|
+
|
20
|
+
cf = ConfigFile.new
|
21
|
+
cf.read
|
22
|
+
|
23
|
+
es = cf.exclude
|
24
|
+
assert_equal 2, es.size
|
25
|
+
assert es.include?('ignore_this')
|
26
|
+
assert es.include?('and_also_this')
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def write_config_file(content)
|
32
|
+
File.open(File.join(TMP_DIR, '.dropsite', 'config.yml'), 'w') {|f| f.puts content}
|
33
|
+
end
|
34
|
+
end
|