Module: GithubPages::JsonRakeExt
- Included in:
- DeployTask
- Defined in:
- lib/ghpages_deploy/rake/json.rb
Class Method Summary collapse
- .directory_mash ⇒ Object
- .directory_sitemap(files) ⇒ Object
- .expand_lists(directory, whitelist, blacklist) ⇒ Object
- .map_file(marker, path) ⇒ Object
- .mash ⇒ Object
- .sanitize_list(list) ⇒ Object
- .sitemap(directory, output, whitelist, blacklist) ⇒ Object
Instance Method Summary collapse
Class Method Details
.directory_mash ⇒ Object
33 34 35 |
# File 'lib/ghpages_deploy/rake/json.rb', line 33 def directory_mash Hash[dirs: mash, files: []] end |
.directory_sitemap(files) ⇒ Object
12 13 14 |
# File 'lib/ghpages_deploy/rake/json.rb', line 12 def directory_sitemap(files) directory_mash.tap { |root| files.each { |path| map_file(root, path) } } end |
.expand_lists(directory, whitelist, blacklist) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/ghpages_deploy/rake/json.rb', line 26 def (directory, whitelist, blacklist) Dir.chdir(directory) do lists = [whitelist, blacklist].map { |list| sanitize_list(list) } lists.reduce(&:-).select { |f| File.file?(f) } end end |
.map_file(marker, path) ⇒ Object
16 17 18 19 20 |
# File 'lib/ghpages_deploy/rake/json.rb', line 16 def map_file(marker, path) *dirs, file = path.split('/') dirs.each { |dir| marker = marker[:dirs][dir] } marker[:files] << file end |
.mash ⇒ Object
37 38 39 |
# File 'lib/ghpages_deploy/rake/json.rb', line 37 def mash Hash.new { |h, k| h[k] = directory_mash } end |
.sanitize_list(list) ⇒ Object
22 23 24 |
# File 'lib/ghpages_deploy/rake/json.rb', line 22 def sanitize_list(list) list.each_with_object(Set.new) { |glob, set| set.merge(Dir[glob]) } end |
.sitemap(directory, output, whitelist, blacklist) ⇒ Object
41 42 43 44 45 46 |
# File 'lib/ghpages_deploy/rake/json.rb', line 41 def sitemap(directory, output, whitelist, blacklist) files = (directory, whitelist, blacklist) map = directory_sitemap(files) File.open(output, 'w+') { |f| f.puts map.to_json } end |
Instance Method Details
#generate_json_sitemap(directory: '.', output: 'sitemap.json', whitelist: ['**/*'], blacklist: []) ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/ghpages_deploy/rake/json.rb', line 49 def generate_json_sitemap( directory: '.', output: 'sitemap.json', whitelist: ['**/*'], blacklist: [] ) handler.handle_deploy do JsonRakeExt.sitemap(directory, output, whitelist, blacklist) [output] end end |