octopress 3.0.0.alpha2 → 3.0.0.alpha3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +6 -14
- data/.gitignore +15 -18
- data/Gemfile +3 -1
- data/LICENSE +20 -0
- data/README.md +66 -0
- data/Rakefile +1 -76
- data/bin/octopress +14 -58
- data/lib/octopress.rb +40 -79
- data/lib/octopress/command.rb +10 -4
- data/lib/octopress/commands/new.rb +50 -12
- data/lib/octopress/commands/publish.rb +18 -0
- data/lib/octopress/core_ext.rb +1 -0
- data/lib/octopress/draft.rb +43 -0
- data/lib/octopress/page.rb +109 -0
- data/lib/octopress/post.rb +30 -0
- data/lib/octopress/version.rb +1 -1
- data/octopress.gemspec +7 -32
- metadata +31 -437
- data/.editorconfig +0 -22
- data/.gitattributes +0 -1
- data/.powrc +0 -4
- data/.rspec +0 -5
- data/.rubocop.yml +0 -119
- data/.slugignore +0 -3
- data/.travis.yml +0 -6
- data/CHANGELOG.markdown +0 -46
- data/CONTRIBUTING.markdown +0 -17
- data/README.markdown +0 -37
- data/lib/console +0 -17
- data/lib/guard/jekyll.rb +0 -33
- data/lib/octopress/commands.rb +0 -14
- data/lib/octopress/commands/build.rb +0 -17
- data/lib/octopress/commands/build_javascripts.rb +0 -11
- data/lib/octopress/commands/build_jekyll.rb +0 -42
- data/lib/octopress/commands/build_stylesheets.rb +0 -13
- data/lib/octopress/commands/install.rb +0 -44
- data/lib/octopress/commands/scaffold.rb +0 -102
- data/lib/octopress/commands/serve.rb +0 -25
- data/lib/octopress/configuration.rb +0 -237
- data/lib/octopress/dependency_installer.rb +0 -287
- data/lib/octopress/errors.rb +0 -3
- data/lib/octopress/filters/content.rb +0 -66
- data/lib/octopress/filters/date.rb +0 -46
- data/lib/octopress/filters/post.rb +0 -175
- data/lib/octopress/filters/url.rb +0 -34
- data/lib/octopress/formatters.rb +0 -9
- data/lib/octopress/formatters/base_formatter.rb +0 -17
- data/lib/octopress/formatters/simple_formatter.rb +0 -9
- data/lib/octopress/formatters/verbose_formatter.rb +0 -9
- data/lib/octopress/generators/category_generator.rb +0 -196
- data/lib/octopress/generators/sitemap_generator.rb +0 -308
- data/lib/octopress/guardfile +0 -43
- data/lib/octopress/helpers/titlecase.rb +0 -37
- data/lib/octopress/ink.rb +0 -12
- data/lib/octopress/inquirable_string.rb +0 -12
- data/lib/octopress/installer.rb +0 -96
- data/lib/octopress/js_assets_manager.rb +0 -97
- data/lib/octopress/liquid_helpers/conditional.rb +0 -36
- data/lib/octopress/liquid_helpers/config.rb +0 -58
- data/lib/octopress/liquid_helpers/include.rb +0 -33
- data/lib/octopress/liquid_helpers/url.rb +0 -29
- data/lib/octopress/liquid_helpers/vars.rb +0 -30
- data/lib/octopress/plugin.rb +0 -33
- data/lib/octopress/rake.rb +0 -16
- data/lib/octopress/scaffold/.gitignore +0 -18
- data/lib/octopress/scaffold/site/Gemfile +0 -3
- data/lib/octopress/scaffold/site/config.ru +0 -25
- data/lib/octopress/scaffold/site/config/compass.rb +0 -27
- data/lib/octopress/scaffold/site/config/rack.rb +0 -25
- data/lib/octopress/scaffold/site/config/site.yml +0 -0
- data/lib/octopress/scaffold/site/javascripts/lib/ios-rotate-scaling-fix.js +0 -19
- data/lib/octopress/scaffold/site/javascripts/lib/jquery-1.9.1.js +0 -9598
- data/lib/octopress/scaffold/site/javascripts/lib/jquery.cookie.js +0 -93
- data/lib/octopress/scaffold/site/stylesheets/_config.scss +0 -1
- data/lib/octopress/scaffold/site/stylesheets/_style.scss +0 -1
- data/lib/octopress/scaffold/site/stylesheets/site.scss +0 -16
- data/lib/octopress/tags/assign.rb +0 -34
- data/lib/octopress/tags/capture.rb +0 -31
- data/lib/octopress/tags/config-tag.rb +0 -23
- data/lib/octopress/tags/include.rb +0 -63
- data/lib/octopress/tags/js-assets.rb +0 -23
- data/lib/octopress/tags/puts.rb +0 -39
- data/lib/octopress/tags/render-partial.rb +0 -89
- data/lib/octopress/tags/return.rb +0 -21
- data/lib/rake/clean.rake +0 -8
- data/lib/rake/clobber.rake +0 -5
- data/lib/rake/console.rake +0 -5
- data/lib/rake/deploy.rake +0 -4
- data/lib/rake/gen_deploy.rake +0 -2
- data/lib/rake/generate.rake +0 -4
- data/lib/rake/generate_only.rake +0 -14
- data/lib/rake/hygiene.rake +0 -29
- data/lib/rake/install.rake +0 -8
- data/lib/rake/integrate.rake +0 -4
- data/lib/rake/isolate.rake +0 -13
- data/lib/rake/list_drafts.rake +0 -7
- data/lib/rake/new.rake +0 -7
- data/lib/rake/new_page.rake +0 -49
- data/lib/rake/new_post.rake +0 -32
- data/lib/rake/nuke.rake +0 -4
- data/lib/rake/preview.rake +0 -4
- data/lib/rake/push.rake +0 -37
- data/lib/rake/rsync.rake +0 -20
- data/lib/rake/set_root_dir.rake +0 -35
- data/lib/rake/setup_github_pages.rake +0 -115
- data/lib/rake/watch.rake +0 -11
- data/lib/scaffold/Rakefile +0 -142
- data/lib/scaffold/plugin-name.gemspec +0 -43
- data/lib/spec/fixtures/env/defaults/classic.yml +0 -2
- data/lib/spec/fixtures/no_override/defaults/classic.yml +0 -11
- data/lib/spec/fixtures/override/defaults/classic.yml +0 -11
- data/lib/spec/fixtures/override/site.yml +0 -11
- data/lib/spec/octopress/configuration_spec.rb +0 -67
- data/lib/spec/octopress/dependency_installer_spec.rb +0 -66
- data/lib/spec/octopress/ink_spec.rb +0 -10
- data/lib/spec/octopress/octopress_spec.rb +0 -97
- data/lib/spec/spec_helper.rb +0 -22
- data/lib/spec/support/env.rb +0 -36
- data/lib/spec/support/simplecov.rb +0 -52
@@ -1,102 +0,0 @@
|
|
1
|
-
module Octopress
|
2
|
-
module Commands
|
3
|
-
class Scaffold < Command
|
4
|
-
SCAFFOLD_DIR = File.join(Octopress.lib_root, "scaffold")
|
5
|
-
|
6
|
-
SCAFFOLD_DIRS = %w[
|
7
|
-
configs
|
8
|
-
includes
|
9
|
-
layouts
|
10
|
-
lib
|
11
|
-
lib/rake
|
12
|
-
javascripts
|
13
|
-
javascripts/lib
|
14
|
-
javascripts/modules
|
15
|
-
source
|
16
|
-
stylesheets
|
17
|
-
plugins
|
18
|
-
]
|
19
|
-
|
20
|
-
class << self
|
21
|
-
def process(args, options)
|
22
|
-
type, plugin_name = process_args(args)
|
23
|
-
|
24
|
-
create_scaffold(type, plugin_name)
|
25
|
-
end
|
26
|
-
|
27
|
-
####################
|
28
|
-
# Scaffolding
|
29
|
-
####################
|
30
|
-
|
31
|
-
def create_scaffold(type, plugin_name)
|
32
|
-
Octopress.logger.info "Scaffolding a new Octopress #{type} in ./#{plugin_name}..."
|
33
|
-
FileUtils.mkdir(plugin_name)
|
34
|
-
Dir.chdir(plugin_name) do
|
35
|
-
FileUtils.mkdir(SCAFFOLD_DIRS)
|
36
|
-
FileUtils.mkdir("lib/#{ruby_name(plugin_name)}")
|
37
|
-
FileUtils.cp(scaffold_file("Rakefile"), "Rakefile")
|
38
|
-
FileUtils.cp(scaffold_file("plugin-name.gemspec"), "#{plugin_name}.gemspec")
|
39
|
-
File.open("MANIFEST.yml", "w") { |f| f.write(plugin_yaml(plugin_name, type)) }
|
40
|
-
File.open("lib/#{ruby_name(plugin_name)}.rb", "w") do |f|
|
41
|
-
f.puts "require 'octopress'"
|
42
|
-
f.puts
|
43
|
-
f.puts "class #{plugin_class(plugin_name)} < Octopress::Plugin"
|
44
|
-
f.puts " ROOT = File.expand_path('../../', __FILE__)"
|
45
|
-
f.puts "end"
|
46
|
-
end
|
47
|
-
File.open("Gemfile", "w") do |f|
|
48
|
-
f.puts "source 'https://rubygems.org'"
|
49
|
-
f.puts
|
50
|
-
f.puts "gemspec"
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
def ruby_name(plugin_name)
|
56
|
-
plugin_name.gsub(/-/, '_')
|
57
|
-
end
|
58
|
-
|
59
|
-
def plugin_yaml(plugin_name, type)
|
60
|
-
plugin_data = {
|
61
|
-
"name" => plugin_name,
|
62
|
-
"slug" => plugin_name,
|
63
|
-
"type" => type,
|
64
|
-
"version" => "0.0.1",
|
65
|
-
"description" => "TODO- Add your description",
|
66
|
-
"summary" => "TODO- Add your summary",
|
67
|
-
"homepage" => "TODO- Add your plugin's homepage",
|
68
|
-
"authors" => ["YOUR NAME"],
|
69
|
-
"emails" => ["YOUREMAIL@EXAMPLE.COM"]
|
70
|
-
}.to_yaml
|
71
|
-
end
|
72
|
-
|
73
|
-
def plugin_class(plugin_name)
|
74
|
-
plugin_name.split("-").map{ |n| n.capitalize }.join("")
|
75
|
-
end
|
76
|
-
|
77
|
-
def scaffold_file(*args)
|
78
|
-
File.join(SCAFFOLD_DIR, *args)
|
79
|
-
end
|
80
|
-
|
81
|
-
####################
|
82
|
-
# Arguments
|
83
|
-
####################
|
84
|
-
|
85
|
-
def process_args(args)
|
86
|
-
validate_args(args)
|
87
|
-
type = args.shift.downcase
|
88
|
-
plugin_name = args.join(" ").downcase.gsub(/[\ \-_]+/, '-')
|
89
|
-
[type, plugin_name]
|
90
|
-
end
|
91
|
-
|
92
|
-
def validate_args(args)
|
93
|
-
if args.size < 2 || !%w[plugin theme].include?(args.first)
|
94
|
-
Octopress.logger.error "Invalid arguments: type must be one of 'plugin'," +
|
95
|
-
"'theme', and a plugin name must follow."
|
96
|
-
raise ArgumentError
|
97
|
-
end
|
98
|
-
end
|
99
|
-
end
|
100
|
-
end
|
101
|
-
end
|
102
|
-
end
|
@@ -1,25 +0,0 @@
|
|
1
|
-
module Octopress
|
2
|
-
module Commands
|
3
|
-
class Serve < Command
|
4
|
-
class << self
|
5
|
-
def process(args, options)
|
6
|
-
Octopress::Commands::Build.process(args, options)
|
7
|
-
serve(args, options)
|
8
|
-
end
|
9
|
-
|
10
|
-
def serve(args, options)
|
11
|
-
guardPid = Process.spawn("guard --guardfile #{Octopress.lib_root}/octopress/guardfile")
|
12
|
-
puts "Starting Rack, serving to http://#{Octopress.configuration[:server_host]}:#{Octopress.configuration[:port]}"
|
13
|
-
rackupPid = Process.spawn("rackup --host #{Octopress.configuration[:server_host]} --port #{Octopress.configuration[:port]}")
|
14
|
-
|
15
|
-
trap("INT") {
|
16
|
-
[guardPid, rackupPid].each { |pid| Process.kill(3, pid) rescue Errno::ESRCH }
|
17
|
-
exit 0
|
18
|
-
}
|
19
|
-
|
20
|
-
[guardPid, rackupPid].each { |pid| Process.wait(pid) }
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
end
|
@@ -1,237 +0,0 @@
|
|
1
|
-
require 'yaml'
|
2
|
-
|
3
|
-
module Octopress
|
4
|
-
class Configuration
|
5
|
-
DEFAULT_CONFIG_DIR = File.join(Octopress.root, 'config')
|
6
|
-
attr_accessor :config_directory
|
7
|
-
|
8
|
-
def initialize(config_dir = DEFAULT_CONFIG_DIR)
|
9
|
-
self.config_directory = config_dir
|
10
|
-
end
|
11
|
-
|
12
|
-
def config_dir(*subdirs)
|
13
|
-
File.expand_path(File.join(*subdirs), self.config_directory)
|
14
|
-
end
|
15
|
-
|
16
|
-
# Static: Reads the configuration of the specified file
|
17
|
-
#
|
18
|
-
# path - the String path to the configuration file, relative to ./_config
|
19
|
-
#
|
20
|
-
# Returns a Hash of the items in the configuration file (symbol keys)
|
21
|
-
def read_config(path)
|
22
|
-
full_path = self.config_dir(path)
|
23
|
-
if File.exists? full_path
|
24
|
-
begin
|
25
|
-
configs = YAML.load(File.open(full_path))
|
26
|
-
if configs.nil?
|
27
|
-
Hash.new
|
28
|
-
else
|
29
|
-
configs.to_symbol_keys
|
30
|
-
end
|
31
|
-
rescue => e
|
32
|
-
puts "Error reading configuration file '#{full_path}':"
|
33
|
-
puts e.message, e.backtrace
|
34
|
-
exit(-1)
|
35
|
-
end
|
36
|
-
else
|
37
|
-
raise ArgumentError, "File at '#{full_path}' does not exist."
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
# Static: Concatenates javacript lib instead of merging (the default behavior for other configs)
|
42
|
-
#
|
43
|
-
# current - current configuration hash
|
44
|
-
# new - hash which hasn't yet been merged
|
45
|
-
#
|
46
|
-
# Returns a concatenated array of javascript lib configurations
|
47
|
-
|
48
|
-
def add_js_lib(current, new)
|
49
|
-
begin
|
50
|
-
new_lib = new[:require_js][:lib]
|
51
|
-
new_lib = [new_lib] unless new_lib.kind_of?(Array)
|
52
|
-
new[:require_js][:lib] = current[:require_js][:lib].concat new_lib
|
53
|
-
rescue
|
54
|
-
end
|
55
|
-
new
|
56
|
-
end
|
57
|
-
|
58
|
-
# Static: Writes the contents of a set of configurations to a path in the config directory
|
59
|
-
#
|
60
|
-
# path - the String path to the configuration file, relative to ./_config
|
61
|
-
# obj - the object to be dumped into the specified file in YAML form
|
62
|
-
#
|
63
|
-
# Returns the Hash for the configuration file.
|
64
|
-
def write_config(path, obj)
|
65
|
-
YAML.dump(obj.to_string_keys, File.open(self.config_dir(path), 'w'))
|
66
|
-
end
|
67
|
-
|
68
|
-
# Static: Reads all the configuration files into one hash
|
69
|
-
#
|
70
|
-
# Returns a Hash of all the configuration files, with each key being a symbol
|
71
|
-
def read_configuration
|
72
|
-
configs = DEFAULTS.dup
|
73
|
-
Dir.glob(self.config_dir('defaults', '**', '*.yml')) do |filename|
|
74
|
-
file_yaml = read_config(filename)
|
75
|
-
unless file_yaml.nil?
|
76
|
-
file_yaml = add_js_lib(configs, file_yaml)
|
77
|
-
configs = configs.deep_merge(file_yaml)
|
78
|
-
end
|
79
|
-
end
|
80
|
-
Dir.glob(self.config_dir('*.yml')) do |filename|
|
81
|
-
file_yaml = read_config(filename)
|
82
|
-
unless file_yaml.nil?
|
83
|
-
file_yaml = add_js_lib(configs, file_yaml)
|
84
|
-
configs = configs.deep_merge(file_yaml)
|
85
|
-
end
|
86
|
-
end
|
87
|
-
|
88
|
-
configs.to_symbol_keys
|
89
|
-
end
|
90
|
-
|
91
|
-
# Static: Writes configuration files necessary for generation of the Jekyll site
|
92
|
-
#
|
93
|
-
# Returns a Hash of the items which were written to the Jekyll configuration file
|
94
|
-
def write_configs_for_generation
|
95
|
-
jekyll_configs = {}
|
96
|
-
|
97
|
-
Dir.chdir(Octopress.root) do
|
98
|
-
File.open("_config.yml", "w") do |f|
|
99
|
-
jekyll_configs = Octopress.configuration.to_string_keys.to_yaml :canonical => false
|
100
|
-
f.write(jekyll_configs)
|
101
|
-
end
|
102
|
-
end
|
103
|
-
|
104
|
-
jekyll_configs
|
105
|
-
end
|
106
|
-
|
107
|
-
# Static: Removes configuration files required for site generation
|
108
|
-
#
|
109
|
-
# Returns the number of files deleted
|
110
|
-
def remove_configs_for_generation
|
111
|
-
Dir.chdir(Octopress.root) do
|
112
|
-
File.unlink("_config.yml")
|
113
|
-
end
|
114
|
-
end
|
115
|
-
|
116
|
-
PostTemplate = YAML.load <<-YAML
|
117
|
-
extension: markdown
|
118
|
-
layout: post
|
119
|
-
title: true
|
120
|
-
date: true
|
121
|
-
categories:
|
122
|
-
YAML
|
123
|
-
|
124
|
-
LinkPostTemplate = YAML.load <<-YAML
|
125
|
-
extension: markdown
|
126
|
-
layout: post
|
127
|
-
title: true
|
128
|
-
date: true
|
129
|
-
external-url:
|
130
|
-
categories:
|
131
|
-
YAML
|
132
|
-
|
133
|
-
PageTemplate = YAML.load <<-YAML
|
134
|
-
extension: html
|
135
|
-
layout: page
|
136
|
-
title: true
|
137
|
-
date: false
|
138
|
-
YAML
|
139
|
-
|
140
|
-
DEFAULTS = {
|
141
|
-
url: 'http://yoursite.com',
|
142
|
-
title: 'My Octopress Blog',
|
143
|
-
subtitle: 'A blogging framework for hackers.',
|
144
|
-
author: 'Your Name',
|
145
|
-
description: '',
|
146
|
-
|
147
|
-
# If publishing to a subdirectory as in http://site.com/project set 'root: /project'
|
148
|
-
root: '/',
|
149
|
-
permalink: '/:year/:month/:day/:title/',
|
150
|
-
source: 'source', # source file directory
|
151
|
-
destination: 'public', # compiled site directory
|
152
|
-
plugins: [
|
153
|
-
"#{Octopress.lib_root}/octopress/liquid_helpers",
|
154
|
-
"#{Octopress.lib_root}/octopress/filters",
|
155
|
-
"#{Octopress.lib_root}/octopress/tags",
|
156
|
-
"#{Octopress.lib_root}/octopress/generators",
|
157
|
-
"plugins"
|
158
|
-
],
|
159
|
-
code_dir: 'downloads/code',
|
160
|
-
category_dir: 'categories',
|
161
|
-
include: ['.htaccess'],
|
162
|
-
|
163
|
-
markdown: 'redcarpet',
|
164
|
-
redcarpet: {
|
165
|
-
extensions: [
|
166
|
-
'no_intra_emphasis',
|
167
|
-
'strikethrough',
|
168
|
-
'autolink',
|
169
|
-
'superscript',
|
170
|
-
'smart',
|
171
|
-
'footnotes',
|
172
|
-
]
|
173
|
-
},
|
174
|
-
|
175
|
-
# Default date format is "ordinal" (resulting in "July 22nd 2007")
|
176
|
-
# You can customize the format as defined in
|
177
|
-
# http://www.ruby-doc.org/core-1.9.2/Time.html#method-i-strftime
|
178
|
-
# Additionally, %o will give you the ordinal representation of the day
|
179
|
-
|
180
|
-
date_format: 'ordinal',
|
181
|
-
env: 'production', # affects asset compilation
|
182
|
-
post_index_dir: 'source', # directory for your posts index page (if you put your index in source/blog/index.html, set this to 'source/blog')
|
183
|
-
stash_dir: '_stash', # directory to stash posts for speedy generation
|
184
|
-
posts_dir: '_posts', # directory for blog files
|
185
|
-
deploy_dir: '_deploy', # directory whose contents are to be deployed
|
186
|
-
new_post_ext: 'markdown', # default new post file extension when using the new_post task
|
187
|
-
new_page_ext: 'markdown', # default new page file extension when using the new_page task
|
188
|
-
titlecase: true, # Converts page and post titles to titlecase
|
189
|
-
server_host: '0.0.0.0', # host ip address for preview server
|
190
|
-
port: 4000, # port for preview server eg. localhost:4000
|
191
|
-
timezone: 'local', # default time and date used to local timezone. Vew supported timezones (under TZ column): http://en.wikipedia.org/wiki/List_of_tz_database_time_zones
|
192
|
-
#paginate_path: page/:num, # default path for pagination, eg. page/2/
|
193
|
-
paginate: 10, # Posts per page on the blog index
|
194
|
-
|
195
|
-
# Templates - these can be overridden in site.yml and themes can ship with their own default templates.
|
196
|
-
|
197
|
-
templates: {
|
198
|
-
post: PostTemplate,
|
199
|
-
linkpost: LinkPostTemplate,
|
200
|
-
page: PageTemplate,
|
201
|
-
},
|
202
|
-
|
203
|
-
|
204
|
-
# Feed settings
|
205
|
-
|
206
|
-
feed: {
|
207
|
-
limit: 20, # Maximum number of posts to include in the feed
|
208
|
-
url: '/feed/', # Link to templates feed
|
209
|
-
email_url: false, # Link to email subscription page (if you offer it)
|
210
|
-
categories: false, # Generate individual feeds for each post category (potential performance hit)
|
211
|
-
author_email: false, # Author email address to the feed
|
212
|
-
},
|
213
|
-
|
214
|
-
# Asset configuration
|
215
|
-
|
216
|
-
# Asset configuration
|
217
|
-
|
218
|
-
# Javascript assets stored in javascripts/lib and javascripts/modules
|
219
|
-
# Are wrapped with CommonJS functions, combined, uglified and fingerprinted
|
220
|
-
# Supported files: .js, .coffee, .mustache, .eco, .tmpl
|
221
|
-
|
222
|
-
# Dependiences from lib are added first as globals
|
223
|
-
require_js: {
|
224
|
-
|
225
|
-
# Dependiences are added first as globals
|
226
|
-
lib: ['jquery-1.9.1.js', 'jquery.cookie.js'],
|
227
|
-
|
228
|
-
# Modules are wrapped with CommonJS functions and must be
|
229
|
-
# Example:
|
230
|
-
# for file: assets/javascripts/modules/some-plugin/awesome.js
|
231
|
-
# require like: var awesome = require('some-plugin/awesome')
|
232
|
-
modules: ['modules']
|
233
|
-
}
|
234
|
-
}
|
235
|
-
end
|
236
|
-
end
|
237
|
-
|
@@ -1,287 +0,0 @@
|
|
1
|
-
require 'uri'
|
2
|
-
require 'open3'
|
3
|
-
require 'fileutils'
|
4
|
-
|
5
|
-
module Octopress
|
6
|
-
class DependencyInstaller
|
7
|
-
|
8
|
-
# Static: installs a list of plugins
|
9
|
-
#
|
10
|
-
# plugins - an Array of plugin names
|
11
|
-
#
|
12
|
-
# Returns nothing
|
13
|
-
def self.install_all(plugins)
|
14
|
-
if plugins.is_a?(String)
|
15
|
-
plugins = [plugins]
|
16
|
-
end
|
17
|
-
installer = DependencyInstaller.new
|
18
|
-
plugins.each do |plugin|
|
19
|
-
installer.install plugin
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
CACHE_DIR = File.join(Octopress.root, ".plugins")
|
24
|
-
USERNAME_REPO_REGEXP = /^([a-z0-9\-_]+)\/([a-z0-9\-_]+)$/
|
25
|
-
OCTOPRESS_REPO_REGEXP = /^[a-z0-9\-_]+$/
|
26
|
-
GIT_REPO_REGEXP = /^(git:\/\/|https:\/\/|git@)([a-z0-9.]+)(\/|:)([a-z0-9\-_]+)\/([a-z0-9\-_]+)\.git/
|
27
|
-
|
28
|
-
# Public: Create a new DependencyInstaller and initialize instance variables
|
29
|
-
#
|
30
|
-
# Returns nothing
|
31
|
-
def initialize(plugins = [])
|
32
|
-
@plugins = Set.new.merge(plugins)
|
33
|
-
end
|
34
|
-
|
35
|
-
# Public: constructs full git URL for a plugin
|
36
|
-
#
|
37
|
-
# plugin - the plugin name
|
38
|
-
#
|
39
|
-
# Returns full git URL for a plugin
|
40
|
-
def git_url(plugin)
|
41
|
-
if OCTOPRESS_REPO_REGEXP.match(plugin)
|
42
|
-
"git://github.com/octopress/#{plugin}.git"
|
43
|
-
elsif USERNAME_REPO_REGEXP.match(plugin)
|
44
|
-
"git://github.com/#{plugin}.git"
|
45
|
-
else
|
46
|
-
plugin
|
47
|
-
end
|
48
|
-
end
|
49
|
-
|
50
|
-
# Public: Gets the directory for local storage
|
51
|
-
#
|
52
|
-
# Returns the directory for the plugin
|
53
|
-
def namespace(plugin)
|
54
|
-
if manifest(plugin)["type"].to_s == "theme"
|
55
|
-
"theme"
|
56
|
-
else
|
57
|
-
manifest(plugin)["slug"]
|
58
|
-
end
|
59
|
-
end
|
60
|
-
|
61
|
-
# Public: builds full installation directory path for plugin
|
62
|
-
#
|
63
|
-
# plugin - the plugin name
|
64
|
-
#
|
65
|
-
# Returns the full path of the installation directory
|
66
|
-
def cache_dir(plugin)
|
67
|
-
FileUtils.mkdir_p(CACHE_DIR) unless File.exists?(CACHE_DIR)
|
68
|
-
File.join(CACHE_DIR, File.basename(plugin).gsub(/\.git$/, ''))
|
69
|
-
end
|
70
|
-
|
71
|
-
# Public: clones the remote repository to the plugin install directory
|
72
|
-
#
|
73
|
-
# plugin - the plugin name
|
74
|
-
#
|
75
|
-
# Returns the file path to where the plugin was installed
|
76
|
-
def clone(plugin)
|
77
|
-
if File.directory?(cache_dir(plugin))
|
78
|
-
Open3.popen3("cd #{cache_dir(plugin)} && git pull origin master") do |stdin, stdout, stderr, wait_thr|
|
79
|
-
exit_status = wait_thr.value
|
80
|
-
raise RuntimeError, "Error updating #{plugin}".red unless exit_status.exitstatus == 0
|
81
|
-
end
|
82
|
-
else
|
83
|
-
Open3.popen3("git clone #{git_url(plugin)} #{cache_dir(plugin)}") do |stdin, stdout, stderr, wait_thr|
|
84
|
-
exit_status = wait_thr.value
|
85
|
-
raise RuntimeError, "Error cloning #{plugin}".red unless exit_status.exitstatus == 0
|
86
|
-
end
|
87
|
-
end
|
88
|
-
cache_dir(plugin)
|
89
|
-
end
|
90
|
-
|
91
|
-
# Public: fetches the contents of the manifest file as a Hash
|
92
|
-
#
|
93
|
-
# plugin - the plugin name
|
94
|
-
#
|
95
|
-
# Returns a Hash of the contents of the manifest file
|
96
|
-
def manifest(plugin)
|
97
|
-
@manifests = {} if @manifests.nil?
|
98
|
-
if @manifests.has_key?(plugin)
|
99
|
-
@manifests[plugin]
|
100
|
-
else
|
101
|
-
@manifests[plugin] = YAML.load_file(File.join(cache_dir(plugin), "manifest.yml"))
|
102
|
-
end
|
103
|
-
end
|
104
|
-
|
105
|
-
# Public: build dependency tree for a plugin
|
106
|
-
#
|
107
|
-
# plugin - the plugin name
|
108
|
-
#
|
109
|
-
# Returns an array of plugin names that are dependencies of the one specified
|
110
|
-
def build_dependencies_tree(plugin)
|
111
|
-
unless @plugins.include?(plugin)
|
112
|
-
clone(plugin)
|
113
|
-
manifest_yml = manifest(plugin)
|
114
|
-
Octopress.logger.debug manifest_yml.to_s
|
115
|
-
return [plugin] if !manifest_yml.has_key?("dependencies") || manifest_yml["dependencies"].size == 0
|
116
|
-
manifest_yml["dependencies"].each do |dep|
|
117
|
-
build_dependencies_tree(dep)
|
118
|
-
end
|
119
|
-
else
|
120
|
-
Octopress.logger.warn "Already installed #{plugin}."
|
121
|
-
end
|
122
|
-
end
|
123
|
-
|
124
|
-
# Public: copy files from the plugin clone to the user's source directory
|
125
|
-
#
|
126
|
-
# plugin - the plugin name
|
127
|
-
#
|
128
|
-
# Returns an Array of file paths which were copied
|
129
|
-
def copy_files(plugin)
|
130
|
-
manifest_yml = manifest(plugin)
|
131
|
-
%w[javascripts stylesheets plugins config source includes].each do |type|
|
132
|
-
Octopress.logger.debug "Copying #{type} files for #{plugin}..."
|
133
|
-
send("copy_#{type}_files", plugin)
|
134
|
-
end
|
135
|
-
end
|
136
|
-
|
137
|
-
# Public: install a plugin and its dependencies
|
138
|
-
#
|
139
|
-
# plugin - the plugin name
|
140
|
-
#
|
141
|
-
# Returns the Array of all plugins installed so far
|
142
|
-
def install(plugin)
|
143
|
-
@plugins.merge(build_dependencies_tree(plugin))
|
144
|
-
@plugins.each do |plugin|
|
145
|
-
copy_files(plugin)
|
146
|
-
end
|
147
|
-
|
148
|
-
@plugins
|
149
|
-
end
|
150
|
-
|
151
|
-
private
|
152
|
-
# Private: Copy file to Octopress installation
|
153
|
-
#
|
154
|
-
# files - a list of files
|
155
|
-
# destination - the directory in which the files should be copied
|
156
|
-
#
|
157
|
-
# Returns nothing
|
158
|
-
def copy_file_list(files, destination)
|
159
|
-
if files.size > 0
|
160
|
-
FileUtils.mkdir_p(destination, verbose: false) unless File.directory?(destination)
|
161
|
-
if files.is_a?(String) && File.directory?(files)
|
162
|
-
Octopress.logger.debug "Copying #{files}/. to #{destination} ..."
|
163
|
-
FileUtils.cp_r "#{files}/.", destination, verbose: false
|
164
|
-
else
|
165
|
-
Octopress.logger.debug "Copying #{files.join(", ")} to #{destination} ..."
|
166
|
-
FileUtils.cp files, destination, verbose: false
|
167
|
-
end
|
168
|
-
end
|
169
|
-
end
|
170
|
-
|
171
|
-
# Private: Fetch list of files in a file recursively
|
172
|
-
#
|
173
|
-
# plugin - plugin name
|
174
|
-
# *subdirs - a
|
175
|
-
def globbed_filelist(plugin, *subdirs)
|
176
|
-
Dir.glob(File.join(cache_dir(plugin), *subdirs, "**", "*")).select do |filename|
|
177
|
-
File.file?(filename)
|
178
|
-
end
|
179
|
-
end
|
180
|
-
|
181
|
-
# Private: Copy source files to local Octopress installation
|
182
|
-
#
|
183
|
-
# plugin - plugin name
|
184
|
-
#
|
185
|
-
# Returns nothing
|
186
|
-
def copy_source_files(plugin)
|
187
|
-
source = File.join(cache_dir(plugin), "source")
|
188
|
-
destination = File.join(Octopress.root, Octopress.configuration[:source])
|
189
|
-
destination = File.join(destination, namespace(plugin)) if manifest(plugin)["type"] != "theme"
|
190
|
-
if File.directory?(source)
|
191
|
-
copy_file_list(source, destination)
|
192
|
-
end
|
193
|
-
end
|
194
|
-
|
195
|
-
# Private: Copy includes files to local Octopress installation
|
196
|
-
#
|
197
|
-
# plugin - plugin name
|
198
|
-
#
|
199
|
-
# Returns nothing
|
200
|
-
def copy_includes_files(plugin)
|
201
|
-
source = File.join(cache_dir(plugin), "includes")
|
202
|
-
destination = File.join(Octopress.root, Octopress.configuration[:source], "_includes", namespace(plugin))
|
203
|
-
if File.directory?(source)
|
204
|
-
copy_file_list(source, destination)
|
205
|
-
end
|
206
|
-
end
|
207
|
-
|
208
|
-
# Private: Copy javascript files to local Octopress installation
|
209
|
-
#
|
210
|
-
# plugin - plugin name
|
211
|
-
# files - the filenames of the stylesheet files for this plugin relative to
|
212
|
-
# the stylesheets dir in the plugin's install dir
|
213
|
-
#
|
214
|
-
# Returns nothing
|
215
|
-
def copy_config_files(plugin)
|
216
|
-
source = File.join(cache_dir(plugin), "configs")
|
217
|
-
destination = File.join(Octopress.root, "config", "defaults", namespace(plugin))
|
218
|
-
if File.directory?(source)
|
219
|
-
copy_file_list(source, destination)
|
220
|
-
end
|
221
|
-
end
|
222
|
-
|
223
|
-
def config_files(plugin)
|
224
|
-
globbed_filelist(plugin, "configs")
|
225
|
-
end
|
226
|
-
|
227
|
-
# Private: Copy javascript files to local Octopress installation
|
228
|
-
#
|
229
|
-
# plugin - plugin name
|
230
|
-
#
|
231
|
-
# Returns nothing
|
232
|
-
def copy_javascripts_files(plugin)
|
233
|
-
source = File.join(cache_dir(plugin), "javascripts", "lib")
|
234
|
-
destination = File.join(Octopress.root, "javascripts", "lib", namespace(plugin))
|
235
|
-
if File.directory?(source)
|
236
|
-
copy_file_list(source, destination)
|
237
|
-
end
|
238
|
-
source = File.join(cache_dir(plugin), "javascripts", "modules")
|
239
|
-
destination = File.join(Octopress.root, "javascripts", "modules", namespace(plugin))
|
240
|
-
if File.directory?(source)
|
241
|
-
copy_file_list(source, destination)
|
242
|
-
end
|
243
|
-
end
|
244
|
-
|
245
|
-
# Private: Copy javascript files to local Octopress installation
|
246
|
-
#
|
247
|
-
# plugin - plugin name
|
248
|
-
# files - the filenames of the stylesheet files for this plugin relative to
|
249
|
-
# the stylesheets dir in the plugin's install dir
|
250
|
-
#
|
251
|
-
# Returns nothing
|
252
|
-
def copy_stylesheets_files(plugin)
|
253
|
-
source = File.join(cache_dir(plugin), "stylesheets")
|
254
|
-
sass_dir = File.join(Octopress.root, "stylesheets")
|
255
|
-
namespace = namespace(plugin)
|
256
|
-
|
257
|
-
if namespace == 'theme'
|
258
|
-
destination = File.join(sass_dir, namespace(plugin))
|
259
|
-
else
|
260
|
-
destination = File.join(sass_dir, 'plugins', namespace(plugin))
|
261
|
-
end
|
262
|
-
if File.directory?(source)
|
263
|
-
copy_file_list(source, destination)
|
264
|
-
end
|
265
|
-
end
|
266
|
-
|
267
|
-
# Private: Copy javascript files to local Octopress installation
|
268
|
-
#
|
269
|
-
# plugin - plugin name
|
270
|
-
# files - the filenames of the Jekyll plugin files for this plugin relative
|
271
|
-
# to the plugin dir in the plugin's install dir
|
272
|
-
#
|
273
|
-
# Returns nothing
|
274
|
-
def copy_plugins_files(plugin)
|
275
|
-
source = File.join(cache_dir(plugin), "plugins")
|
276
|
-
install_dir = Octopress.configuration[:plugins].is_a?(Array) ? Octopress.configuration[:plugins].last : Octopress.configuration[:plugins]
|
277
|
-
destination = File.join(Octopress.root, install_dir, namespace(plugin))
|
278
|
-
if File.directory?(source)
|
279
|
-
copy_file_list(source, destination)
|
280
|
-
end
|
281
|
-
end
|
282
|
-
|
283
|
-
def plugin_files(plugin)
|
284
|
-
globbed_filelist(plugin, "plugins")
|
285
|
-
end
|
286
|
-
end
|
287
|
-
end
|