power-build 1.0.0 → 1.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 +4 -4
- data/README.md +47 -10
- data/lib/assets/css/custom.css +0 -40
- data/lib/assets/css/theme.css +59 -0
- data/lib/assets/js/theme.js +0 -0
- data/lib/assets/partials/_footer.html.erb +13 -4
- data/lib/assets/partials/_head.html.erb +1 -0
- data/lib/assets/power-build.config +4 -0
- data/lib/assets/templates/category.html.erb +1 -6
- data/lib/assets/templates/index.html.erb +2 -6
- data/lib/assets/templates/show.html.erb +1 -6
- data/lib/power-build/base.rb +40 -21
- data/lib/power-build/constructor.rb +47 -80
- data/lib/power-build/helper.rb +26 -0
- data/lib/power-build/i18n.rb +28 -0
- data/lib/power-build/version.rb +1 -1
- metadata +5 -2
- data/lib/assets/js/bootstrap.js +0 -2306
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 24f12087f935cb4d1c84126aed880d578539d367
|
4
|
+
data.tar.gz: fd5e8bec4bd26673386cf6adf9676a8f7d880891
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fd49c7a04878622724aa7594823a496e3d8bd8c321ad3dbc1a965bde47acd04fb1f20feb7b6a30803306a1297a4eca5c79bf3e7568baaa05b4620a8d81763556
|
7
|
+
data.tar.gz: 993d884a1e6d171f53b76105d70ae6519f8b7cc01cc081d17351de1a6a94e0ba131b9958ce03450bb47f57d29893f23184a0ade07d30b119de14b940fb09cf72
|
data/README.md
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
# Power Build
|
2
2
|
|
3
|
-
|
3
|
+
[](http://badge.fury.io/rb/power-build) [](https://codeclimate.com/github/nkj20932/power-build)
|
4
4
|
|
5
|
-
|
5
|
+
Power Build is a photo album builder which generates a site based on the images in a project. It works from command line.
|
6
|
+
|
7
|
+
#### [Demo Site](https://github.com/nkj20932/image_stack/tree/gh-pages)
|
6
8
|
|
7
9
|
## Requirement
|
8
10
|
|
@@ -34,7 +36,7 @@ It creates a config file in your project directory. You can adjust the content d
|
|
34
36
|
$power build
|
35
37
|
```
|
36
38
|
|
37
|
-
You can skip the `build` and just run `power`. This command generates a static site which allows you to host on github pages. Basically it creates a `index.html` and a folder `assets` with other
|
39
|
+
You can skip the `build` and just run `power`. This command generates a static site which allows you to host on github pages. Basically it creates a `index.html` and a folder `assets` with other stuff in it.
|
38
40
|
|
39
41
|
```
|
40
42
|
$power delete
|
@@ -42,6 +44,12 @@ $power delete
|
|
42
44
|
|
43
45
|
Clean all files generated by power-build.
|
44
46
|
|
47
|
+
Further commands and shortcuts will display at:
|
48
|
+
|
49
|
+
```
|
50
|
+
$power help
|
51
|
+
```
|
52
|
+
|
45
53
|
## Config
|
46
54
|
|
47
55
|
The config file looks like this:
|
@@ -76,7 +84,7 @@ My_project_folder
|
|
76
84
|
|-- image_root_folder
|
77
85
|
```
|
78
86
|
|
79
|
-
If so,
|
87
|
+
If so, your folder will look like this after site generation:
|
80
88
|
|
81
89
|
```
|
82
90
|
My_project_folder
|
@@ -86,21 +94,50 @@ My_project_folder
|
|
86
94
|
|-- index.html
|
87
95
|
```
|
88
96
|
|
89
|
-
|
97
|
+
Everything in your project root folder will be ignored. Files already in your `assets` directory will not be overwritten during build, so any change in `custom.js` or `custom.css` will preserve.
|
98
|
+
|
99
|
+
## Image Arrangement
|
100
|
+
|
101
|
+
The image folder should be stored by categories like this:
|
90
102
|
|
91
103
|
```
|
92
104
|
image_root_folder
|
93
105
|
|-- category_1
|
94
|
-
| |-- image_1
|
95
|
-
| |-- image_2
|
96
|
-
| |-- image_3
|
106
|
+
| |-- image_1.jpg
|
107
|
+
| |-- image_2.png
|
108
|
+
| |-- image_3.gif
|
97
109
|
|
|
98
110
|
|-- category_2
|
99
111
|
|-- category_3
|
112
|
+
|-- image_1.jpg
|
113
|
+
|-- image_2.png
|
114
|
+
```
|
115
|
+
|
116
|
+
All images will be categorized with their folder name. Images not in a subfolder will be categorized as "Uncategorized". For example:
|
117
|
+
|
118
|
+
```
|
119
|
+
my_album/
|
120
|
+
|-- family/
|
121
|
+
| |-- brother.jpg
|
122
|
+
| |-- mother.png
|
123
|
+
| |-- sister.gif
|
124
|
+
|
|
125
|
+
|-- my_life/
|
126
|
+
|-- my_pet/
|
127
|
+
|-- James Bond.jpg
|
128
|
+
|-- Samuel Jackson.png
|
100
129
|
```
|
101
130
|
|
102
|
-
|
131
|
+
`brother.jpg` will be labelled as "family", while `James Bond.jpg` and `Samuel Jacson.png` will be labelled as "Uncategorized".
|
132
|
+
|
133
|
+
Only this structure followed can the site be generated in the correct format as in the [demo](https://github.com/nkj20932/image_stack/tree/gh-pages).
|
134
|
+
|
135
|
+
## Deployment
|
136
|
+
|
137
|
+
After generation, push from the branch `gh-pages` to Github and enjoy.
|
138
|
+
|
139
|
+
#### [GitHub Pages Hosting Instruction](https://pages.github.com/)
|
103
140
|
|
104
141
|
## Issues & Contribution
|
105
142
|
|
106
|
-
The project follows MIT Licence. Any issue, pull-request, feature-request, or comment is
|
143
|
+
The project follows MIT Licence. Any issue, pull-request, feature-request, or comment is welcomed.
|
data/lib/assets/css/custom.css
CHANGED
@@ -1,40 +0,0 @@
|
|
1
|
-
/*!
|
2
|
-
* Start Bootstrap - Thumbnail Gallery HTML Template (http://startbootstrap.com)
|
3
|
-
* Code licensed under the Apache License v2.0.
|
4
|
-
* For details, see http://www.apache.org/licenses/LICENSE-2.0.
|
5
|
-
*/
|
6
|
-
|
7
|
-
body {
|
8
|
-
padding-top: 70px; /* Required padding for .navbar-fixed-top. Change if height of navigation changes. */
|
9
|
-
}
|
10
|
-
|
11
|
-
.thumb {
|
12
|
-
margin-bottom: 30px;
|
13
|
-
}
|
14
|
-
|
15
|
-
footer {
|
16
|
-
margin: 50px 0;
|
17
|
-
}
|
18
|
-
|
19
|
-
img.img-responsive {
|
20
|
-
height: 200px;
|
21
|
-
}
|
22
|
-
|
23
|
-
img.image-responsive.single-image {
|
24
|
-
max-width: 1140px;
|
25
|
-
display: block;
|
26
|
-
margin: 0 auto;
|
27
|
-
}
|
28
|
-
|
29
|
-
.download, .home {
|
30
|
-
margin-top: 30px;
|
31
|
-
}
|
32
|
-
|
33
|
-
.home {
|
34
|
-
margin-left: 20px;
|
35
|
-
}
|
36
|
-
|
37
|
-
.copyright {
|
38
|
-
color: #C2C2C2;
|
39
|
-
margin-top: -25px;
|
40
|
-
}
|
@@ -0,0 +1,59 @@
|
|
1
|
+
/*!
|
2
|
+
* Start Bootstrap - Thumbnail Gallery HTML Template (http://startbootstrap.com)
|
3
|
+
* Code licensed under the Apache License v2.0.
|
4
|
+
* For details, see http://www.apache.org/licenses/LICENSE-2.0.
|
5
|
+
*/
|
6
|
+
|
7
|
+
body {
|
8
|
+
padding-top: 70px; /* Required padding for .navbar-fixed-top. Change if height of navigation changes. */
|
9
|
+
}
|
10
|
+
|
11
|
+
.thumb {
|
12
|
+
margin-bottom: 30px;
|
13
|
+
}
|
14
|
+
|
15
|
+
footer {
|
16
|
+
margin: 50px 0;
|
17
|
+
}
|
18
|
+
|
19
|
+
img.img-responsive {
|
20
|
+
height: 200px;
|
21
|
+
}
|
22
|
+
|
23
|
+
img.image-responsive.single-image {
|
24
|
+
max-width: 1140px;
|
25
|
+
display: block;
|
26
|
+
margin: 0 auto;
|
27
|
+
}
|
28
|
+
|
29
|
+
.download, .home {
|
30
|
+
margin-top: 30px;
|
31
|
+
}
|
32
|
+
|
33
|
+
.home {
|
34
|
+
margin-left: 20px;
|
35
|
+
}
|
36
|
+
|
37
|
+
.copyright {
|
38
|
+
color: #C2C2C2;
|
39
|
+
margin-top: -25px;
|
40
|
+
}
|
41
|
+
|
42
|
+
.btn {
|
43
|
+
margin-left: 10px;
|
44
|
+
margin-right: 10px;
|
45
|
+
}
|
46
|
+
|
47
|
+
@media all and (max-width: 600px) {
|
48
|
+
img.img-responsive {
|
49
|
+
height: 100px;
|
50
|
+
}
|
51
|
+
|
52
|
+
h1.page-header {
|
53
|
+
font-size: 26px;
|
54
|
+
}
|
55
|
+
|
56
|
+
img.image-responsive.single-image {
|
57
|
+
max-width: 100%;
|
58
|
+
}
|
59
|
+
}
|
File without changes
|
@@ -1,8 +1,17 @@
|
|
1
1
|
<footer>
|
2
|
-
<div class="row">
|
3
|
-
|
4
|
-
|
2
|
+
<div class="row">
|
3
|
+
<% if copyright_display %>
|
4
|
+
<div class="copyright col-lg-12 text-center">
|
5
|
+
<p><%= i_copyright %> <%= "#{title} " %><%= Time.now.strftime("%Y") %></p>
|
6
|
+
</div>
|
7
|
+
<% end %>
|
5
8
|
</div>
|
6
|
-
|
9
|
+
<script src="<%= resource_prefix %>assets/js/jquery.js"></script>
|
10
|
+
<script src="<%= resource_prefix %>assets/js/bootstrap.min.js"></script>
|
11
|
+
<script src="<%= resource_prefix %>assets/js/theme.js"></script>
|
12
|
+
<script src="<%= resource_prefix %>assets/js/custom.js"></script>
|
13
|
+
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/zclip/1.1.2/jquery.zclip.js"></script> -->
|
7
14
|
</footer>
|
15
|
+
<!-- The credit of this design goes to David Miller -->
|
16
|
+
<!-- Check more for detail: http://startbootstrap.com/template-overviews/thumbnail-gallery/ -->
|
8
17
|
|
@@ -6,5 +6,6 @@
|
|
6
6
|
<meta name="author" content="">
|
7
7
|
<link href="<%= resource_prefix %>assets/css/bootstrap.min.css" rel="stylesheet">
|
8
8
|
<link href="<%= resource_prefix %>assets/css/custom.css" rel="stylesheet">
|
9
|
+
<link href="<%= resource_prefix %>assets/css/theme.css" rel="stylesheet">
|
9
10
|
<title><%= title %></title>
|
10
11
|
</head>
|
@@ -11,7 +11,7 @@
|
|
11
11
|
<% current_category[:images].each do |image| %>
|
12
12
|
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
|
13
13
|
<a class="thumbnail" href="<%= image %>.html">
|
14
|
-
<img class="img-responsive" src='<%= "#{resource_prefix}#{root_folder}
|
14
|
+
<img class="img-responsive" src='<%= "#{resource_prefix}#{root_folder}#{bridge}/#{image}" %>' alt="">
|
15
15
|
</a>
|
16
16
|
</div>
|
17
17
|
<% end %>
|
@@ -19,10 +19,5 @@
|
|
19
19
|
<hr>
|
20
20
|
<%= footer %>
|
21
21
|
</div>
|
22
|
-
<script src="<%= resource_prefix %>assets/js/jquery.js"></script>
|
23
|
-
<script src="<%= resource_prefix %>assets/js/bootstrap.min.js"></script>
|
24
|
-
<script src="<%= resource_prefix %>assets/js/custom.js"></script>
|
25
22
|
</body>
|
26
|
-
<!-- The credit of this design goes to David Miller -->
|
27
|
-
<!-- Check more for detail: http://startbootstrap.com/template-overviews/thumbnail-gallery/ -->
|
28
23
|
</html>
|
@@ -9,10 +9,11 @@
|
|
9
9
|
<h1 class="page-header"><%= i_header %></h1>
|
10
10
|
</div>
|
11
11
|
<% image_collection.each do |category| %>
|
12
|
+
<% bridge = category[:tag] == i_uncategorized ? "" : "/#{category[:tag]}" %>
|
12
13
|
<% category[:images].each do |image| %>
|
13
14
|
<div class="col-lg-3 col-md-4 col-xs-6 thumb">
|
14
15
|
<a class="thumbnail" href="<%= "assets/#{category[:tag]}/#{image}.html" %>">
|
15
|
-
<img class="img-responsive" src='<%= "#{root_folder}
|
16
|
+
<img class="img-responsive" src='<%= "#{root_folder}#{bridge}/#{image}" %>' alt="">
|
16
17
|
</a>
|
17
18
|
</div>
|
18
19
|
<% end %>
|
@@ -21,10 +22,5 @@
|
|
21
22
|
<hr>
|
22
23
|
<%= footer %>
|
23
24
|
</div>
|
24
|
-
<script src="assets/js/jquery.js"></script>
|
25
|
-
<script src="assets/js/bootstrap.min.js"></script>
|
26
|
-
<script src="assets/js/custom.js"></script>
|
27
25
|
</body>
|
28
|
-
<!-- The credit of this design goes to David Miller -->
|
29
|
-
<!-- Check more for detail: http://startbootstrap.com/template-overviews/thumbnail-gallery/ -->
|
30
26
|
</html>
|
@@ -9,7 +9,7 @@
|
|
9
9
|
<h1 class="page-header"><a href="../../index.html"><%= i_header %></a> > <a href="index.html"><%= current_category[:tag] %></a> > <%= title %></h1>
|
10
10
|
<img class="image-responsive single-image" src="<%= current_image_source %>" alt="">
|
11
11
|
<div class="text-center">
|
12
|
-
<a class="btn btn-lg btn-primary download" href="<%= current_image_source %>" download="<%= title %>"
|
12
|
+
<a class="btn btn-lg btn-primary download" href="<%= current_image_source %>" download="<%= title %>" ><%= i_download %></a>
|
13
13
|
<a class="btn btn-lg btn-default home" href="<%= resource_prefix %>index.html"><%= i_home %></a>
|
14
14
|
</div>
|
15
15
|
</div>
|
@@ -17,10 +17,5 @@
|
|
17
17
|
<hr>
|
18
18
|
<%= footer %>
|
19
19
|
</div>
|
20
|
-
<script src="<%= resource_prefix %>assets/js/jquery.js"></script>
|
21
|
-
<script src="<%= resource_prefix %>assets/js/bootstrap.min.js"></script>
|
22
|
-
<script src="<%= resource_prefix %>assets/js/custom.js"></script>
|
23
20
|
</body>
|
24
|
-
<!-- The credit of this design goes to David Miller -->
|
25
|
-
<!-- Check more for detail: http://startbootstrap.com/template-overviews/thumbnail-gallery/ -->
|
26
21
|
</html>
|
data/lib/power-build/base.rb
CHANGED
@@ -9,23 +9,19 @@ module PowerBuild
|
|
9
9
|
map %w[b] => :build
|
10
10
|
default_task :build
|
11
11
|
def build
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
puts "No config file found. Run 'power init' first."
|
18
|
-
end
|
12
|
+
config_exists?
|
13
|
+
image_root_folder_exists?
|
14
|
+
Constructor.new.copy_assets
|
15
|
+
Constructor.new(:config).generate_site
|
16
|
+
puts "Done!"
|
19
17
|
end
|
20
18
|
|
21
19
|
desc "init, i", "Start with a config file."
|
22
20
|
map %w[i] => :init
|
23
21
|
def init
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
puts "Already in a power-build project."
|
28
|
-
end
|
22
|
+
config_already_exists?
|
23
|
+
in_power_build_project?
|
24
|
+
Constructor.new.build_config
|
29
25
|
end
|
30
26
|
|
31
27
|
desc "delete, d", "Remove all files generated by Power Build"
|
@@ -34,12 +30,6 @@ module PowerBuild
|
|
34
30
|
Constructor.new.remove_config
|
35
31
|
end
|
36
32
|
|
37
|
-
desc "config, open, o", "Open the config file for you if you're this lazy"
|
38
|
-
map %w[open, o] => :config
|
39
|
-
def config
|
40
|
-
Constructor.new.open_config
|
41
|
-
end
|
42
|
-
|
43
33
|
map %w[--version -v] => :__print_version
|
44
34
|
desc "--version, -v", "show version"
|
45
35
|
def __print_version
|
@@ -53,12 +43,41 @@ module PowerBuild
|
|
53
43
|
# end
|
54
44
|
|
55
45
|
private
|
56
|
-
def in_power_build_project
|
46
|
+
def in_power_build_project?
|
57
47
|
count = Dir.pwd.count("/") - 1
|
48
|
+
find_config = false
|
58
49
|
for i in 0..count do
|
59
|
-
|
50
|
+
find_config = true if File.file?("../" * i + "power-build.config")
|
51
|
+
end
|
52
|
+
if find_config
|
53
|
+
puts "Already in a power-build project."
|
54
|
+
abort
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def config_exists?
|
59
|
+
unless File.file? "power-build.config"
|
60
|
+
puts "No config file found. Run 'power init' first."
|
61
|
+
abort
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
def config_already_exists?
|
66
|
+
if File.file? "power-build.config"
|
67
|
+
puts "Config file already exists. Either:"
|
68
|
+
puts "1. Run 'power build' to build."
|
69
|
+
puts "2. Run 'power delete' to delete all."
|
70
|
+
abort
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def image_root_folder_exists?
|
75
|
+
config = Helper.read_config
|
76
|
+
folder = config["root_folder"]
|
77
|
+
unless File.directory? folder
|
78
|
+
puts "Image folder '#{folder}' not found."
|
79
|
+
abort
|
60
80
|
end
|
61
|
-
return @respond
|
62
81
|
end
|
63
82
|
end
|
64
83
|
end
|
@@ -2,26 +2,21 @@ require 'colorize'
|
|
2
2
|
require 'erb'
|
3
3
|
require 'ostruct'
|
4
4
|
require 'json'
|
5
|
+
require 'power-build/helper'
|
6
|
+
require 'power-build/i18n'
|
5
7
|
|
6
8
|
module PowerBuild
|
7
9
|
class Constructor
|
8
|
-
|
9
10
|
def initialize(config=nil)
|
10
11
|
@assets_base = "../../assets"
|
11
12
|
variables_set if config
|
12
13
|
end
|
13
14
|
|
14
15
|
def build_config
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
else
|
20
|
-
@assets_base = "../../assets"
|
21
|
-
config = "power-build.config"
|
22
|
-
FileUtils.cp File.expand_path("#{@assets_base}/power-build.config", __FILE__), config
|
23
|
-
puts "Created: ".green + "power-build.config"
|
24
|
-
end
|
16
|
+
@assets_base = "../../assets"
|
17
|
+
config = "power-build.config"
|
18
|
+
FileUtils.cp File.expand_path("#{@assets_base}/power-build.config", __FILE__), config
|
19
|
+
puts "Created: ".green + "power-build.config"
|
25
20
|
end
|
26
21
|
|
27
22
|
def copy_assets
|
@@ -51,7 +46,7 @@ module PowerBuild
|
|
51
46
|
@variables.title = @config["title"]
|
52
47
|
@variables.resource_prefix = ""
|
53
48
|
update_partials
|
54
|
-
|
49
|
+
render_("index")
|
55
50
|
puts "Created: ".green + "index.html"
|
56
51
|
end
|
57
52
|
|
@@ -59,8 +54,6 @@ module PowerBuild
|
|
59
54
|
if File.file? "power-build.config"
|
60
55
|
FileUtils.remove "power-build.config"
|
61
56
|
puts "Removed:".red + " power-build.config"
|
62
|
-
else
|
63
|
-
puts "Config file does not exist."
|
64
57
|
end
|
65
58
|
if File.directory? "assets"
|
66
59
|
FileUtils.rm_rf "assets"
|
@@ -72,26 +65,19 @@ module PowerBuild
|
|
72
65
|
end
|
73
66
|
end
|
74
67
|
|
75
|
-
def open_config
|
76
|
-
if File.file? "power-build.config"
|
77
|
-
%x[open power-build.config]
|
78
|
-
else
|
79
|
-
puts "Config file does not exist."
|
80
|
-
end
|
81
|
-
end
|
82
|
-
|
83
68
|
private
|
84
69
|
|
85
70
|
def variables_set
|
86
|
-
@config = read_config
|
71
|
+
@config = Helper.read_config
|
87
72
|
@variables = OpenStruct.new(title: @config["title"],
|
88
73
|
root_folder: @config["root_folder"],
|
89
74
|
site: @config["site"],
|
90
75
|
host_link: @config["host_link"],
|
91
76
|
host_display_text: @config["host_display_text"],
|
92
|
-
resource_prefix: ""
|
77
|
+
resource_prefix: "",
|
78
|
+
copyright_display: @config["Copyright Display"]
|
93
79
|
)
|
94
|
-
|
80
|
+
I18n.load(@config["language"]).each {|key, value| @variables.send("#{key.to_s}=".to_sym, value) }
|
95
81
|
end
|
96
82
|
|
97
83
|
def copy_assets_dir(dir_name)
|
@@ -115,21 +101,6 @@ module PowerBuild
|
|
115
101
|
end
|
116
102
|
end
|
117
103
|
|
118
|
-
def read_config
|
119
|
-
begin
|
120
|
-
JSON.parse(File.read("power-build.config"))
|
121
|
-
rescue JSON::ParserError
|
122
|
-
puts "============================================================"
|
123
|
-
puts "Oops, make sure 'power-build.config' is in correct JSON format."
|
124
|
-
puts "1. Wrap the whole content in brackets {}"
|
125
|
-
puts "2. Wrap each key and value with quotes ''"
|
126
|
-
puts "3. Separate each setting with comma ,"
|
127
|
-
puts "If you can't fix it, run 'power delete' to start over again."
|
128
|
-
puts "============================================================"
|
129
|
-
raise JSON::ParserError
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
104
|
def update_partials
|
134
105
|
add_partial("head")
|
135
106
|
add_partial("navbar")
|
@@ -142,40 +113,53 @@ module PowerBuild
|
|
142
113
|
@variables.send("#{partial}=".to_sym, rendered)
|
143
114
|
end
|
144
115
|
|
145
|
-
def render_page(page)
|
146
|
-
content = File.read(File.expand_path("#{@assets_base}/templates/#{page}.html.erb", __FILE__))
|
147
|
-
erb = ERB.new(content).result(@variables.instance_eval{binding})
|
148
|
-
File.open("#{page}.html", "w") {|file| file.write(erb)}
|
149
|
-
end
|
150
|
-
|
151
116
|
def collect_images
|
152
117
|
collection = []
|
153
118
|
root_dir = @config["root_folder"]
|
154
|
-
dirs = Dir.entries(root_dir)
|
155
|
-
dirs.delete(".")
|
156
|
-
dirs.delete("..")
|
119
|
+
dirs = Dir.entries(root_dir).delete_folder_extra
|
157
120
|
dirs.each do |dir|
|
158
121
|
if File.directory? "#{root_dir}/#{dir}"
|
159
|
-
images = Dir.entries("#{root_dir}/#{dir}")
|
160
|
-
images.delete(".")
|
161
|
-
images.delete("..")
|
122
|
+
images = Dir.entries("#{root_dir}/#{dir}").delete_folder_extra
|
162
123
|
category = {:tag => dir, :images => []}
|
163
124
|
images.each do |image|
|
164
|
-
if File.file?
|
165
|
-
if ["jpg", "png", "gif", "peg"].include? image[-3..-1].downcase
|
166
|
-
category[:images].push(image)
|
167
|
-
end
|
125
|
+
if File.file?("#{root_dir}/#{dir}/#{image}")
|
126
|
+
category[:images].push(image) if ["jpg", "png", "gif", "peg"].include? image[-3..-1].downcase
|
168
127
|
end
|
169
128
|
end
|
170
129
|
collection.push(category)
|
171
130
|
end
|
172
131
|
end
|
132
|
+
uncategorized = {:tag => @variables[:i_uncategorized], :images => []}
|
133
|
+
dirs.each do |image|
|
134
|
+
if File.file?("#{root_dir}/#{image}") && image.include?(".")
|
135
|
+
uncategorized[:images].push(image) if ["jpg", "png", "gif", "peg"].include? image[-3..-1].downcase
|
136
|
+
end
|
137
|
+
end
|
138
|
+
collection.push(uncategorized) if uncategorized[:images].length > 0
|
139
|
+
|
173
140
|
return collection
|
174
141
|
end
|
175
142
|
|
176
|
-
def
|
143
|
+
def variables_set_by(category)
|
177
144
|
@dir = FileUtils.mkdir_p("assets/#{category[:tag]}").first
|
178
145
|
@variables.current_category = category
|
146
|
+
if category[:tag] == @variables[:i_uncategorized]
|
147
|
+
@variables.bridge = ""
|
148
|
+
else
|
149
|
+
@variables.bridge = "/#{category[:tag]}"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
|
153
|
+
def variables_set_by_each(category, image)
|
154
|
+
@variables.current_image = "#{@dir}/#{image}"
|
155
|
+
bridge = category[:tag] == @variables[:i_uncategorized] ? "" : "/#{category[:tag]}"
|
156
|
+
@variables.current_image_source = "../../#{@config["root_folder"]}#{bridge}/#{image}"
|
157
|
+
@variables.current_title = image
|
158
|
+
@variables.title = @variables.current_title
|
159
|
+
end
|
160
|
+
|
161
|
+
def create_page_by(category)
|
162
|
+
variables_set_by(category)
|
179
163
|
content = File.read(File.expand_path("#{@assets_base}/templates/category.html.erb", __FILE__))
|
180
164
|
erb = ERB.new(content).result(@variables.instance_eval{binding})
|
181
165
|
File.open("#{@dir}/index.html", "w") {|file| file.write(erb)}
|
@@ -183,35 +167,18 @@ module PowerBuild
|
|
183
167
|
end
|
184
168
|
|
185
169
|
def create_page_by_each(category, image)
|
186
|
-
|
187
|
-
@variables.current_image_source = "../../#{@config["root_folder"]}/#{category[:tag]}/#{image}"
|
188
|
-
@variables.current_title = image
|
189
|
-
@variables.title = @variables.current_title
|
170
|
+
variables_set_by_each(category, image)
|
190
171
|
content = File.read(File.expand_path("#{@assets_base}/templates/show.html.erb", __FILE__))
|
191
172
|
erb = ERB.new(content).result(@variables.instance_eval{binding})
|
192
173
|
File.open("#{@dir}/#{@variables.current_title}.html", "w") {|file| file.write(erb)}
|
193
174
|
puts "Created: ".green + "#{@dir}/#{@variables.current_title}.html"
|
194
175
|
end
|
195
176
|
|
196
|
-
def
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
i_header: "總覽",
|
201
|
-
i_category: "類別",
|
202
|
-
i_copyright: "版權所有",
|
203
|
-
i_download: "下載",
|
204
|
-
i_home: "首頁"
|
205
|
-
}
|
206
|
-
when "en"
|
207
|
-
{
|
208
|
-
i_header: "Overview",
|
209
|
-
i_category: "Categories",
|
210
|
-
i_copyright: "Copyright",
|
211
|
-
i_download: "Download",
|
212
|
-
i_home: "Home"
|
213
|
-
}
|
214
|
-
end
|
177
|
+
def render_(index)
|
178
|
+
content = File.read(File.expand_path("#{@assets_base}/templates/index.html.erb", __FILE__))
|
179
|
+
erb = ERB.new(content).result(@variables.instance_eval{binding})
|
180
|
+
File.open("index.html", "w") {|file| file.write(erb)}
|
215
181
|
end
|
182
|
+
|
216
183
|
end
|
217
184
|
end
|