nesta-plugin-subpages 0.5.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/.gitignore ADDED
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in nesta-plugin-subpages.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2012 Randy "Syntruth" Carnahan
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,63 @@
1
+ # Nesta Subpages Plugin
2
+
3
+ Add two new methods to the `Nesta::Page` class that finds any subpages
4
+ for an index page. A subpage is considered to be a sibling page in the
5
+ same directory as the index page and any index pages within immediate
6
+ subdirectories. For example:
7
+
8
+ /content/pages/parent/
9
+ /content/pages/parent/index.mdown
10
+ /content/pages/parent/page-1.mdown
11
+ /content/pages/parent/page-2.mdown
12
+ /content/pages/parent/subdir-1/
13
+ /content/pages/parent/subdir-1/index.haml
14
+ /content/pages/parent/subdir-2/
15
+ /content/pages/parent/subdir-2/some-other-pages.mdown
16
+
17
+ Page.find_by_path('parent').subpages() => [page-1, page-2, subdir-1]
18
+
19
+ The returned array contains the Page instances themselves, not their
20
+ string paths.
21
+
22
+ Lastly, there is also `#has_subpages?` helper method that returns true
23
+ or false if the page has any subpages.
24
+
25
+ Subpages are cached within an instance variable the first time that
26
+ `#subpages` is called, but this should not be a problem in most cases.
27
+
28
+ Also, there is a helper defined called `subpages_for` that takes either
29
+ a Page instance or a string path and returns the same array.
30
+
31
+ ## Installation
32
+
33
+ Add this line to your application's Gemfile:
34
+
35
+ gem 'nesta-plugin-subpages'
36
+
37
+ And then execute:
38
+
39
+ $ bundle
40
+
41
+ Or install it yourself as:
42
+
43
+ $ gem install nesta-plugin-subpages
44
+
45
+ ## Usage
46
+
47
+ Not much to do! Simply call the `#subpages` method on your Page object
48
+ when you want to use the array of subpages! Easy peasy, m'friend. For
49
+ example, in the sidebar, you might do this:
50
+
51
+ - if @page.has_subpages?
52
+ #nav.subpages
53
+ %h1 Subpages
54
+ - display_menu(@page.subpages, :class => "menu")
55
+
56
+
57
+ # Contributing
58
+
59
+ 1. Fork it
60
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
61
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
62
+ 4. Push to the branch (`git push origin my-new-feature`)
63
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,3 @@
1
+ require "nesta-plugin-subpages/version"
2
+
3
+ Nesta::Plugin.register(__FILE__)
@@ -0,0 +1,81 @@
1
+ module Nesta
2
+ module Plugin
3
+ module Subpages
4
+ module Helpers
5
+
6
+ # Helper that takes a page or a string path to a page
7
+ # and returns any subpages if they exist, or an empty
8
+ # array otherwise.
9
+ def subpages_for(page_or_path)
10
+ case page_or_path
11
+ when Page
12
+ return page_or_path.subpages()
13
+ when String
14
+ page = Page.find_by_path(page_or_path)
15
+ return page.subpages if page
16
+ end
17
+
18
+ return []
19
+ end
20
+
21
+ end
22
+ end
23
+ end
24
+
25
+ class Page
26
+ # This method grabs any pages that are siblings of an index
27
+ # page and any index pages in immediate subdirectories. If
28
+ # the page is NOT an index page or there are NO subpages, an
29
+ # empty array is returned.
30
+ def subpages
31
+ return [] unless self.index_page?
32
+ return @subpages if @subpages
33
+
34
+ pth = File.dirname(self.filename)
35
+ mpth = Page.model_path # Just cacheing these two for
36
+ fmts = FORMATS.join('|') # use below.
37
+ pages = []
38
+
39
+ Dir.foreach(pth) do |entry|
40
+ # Skip the dot-dirs and any index page in the current
41
+ # directory.
42
+ next if entry == '.' or entry == '..' or entry.match(/^index/)
43
+
44
+ entry = File.join(pth, entry)
45
+
46
+ if File.directory?(entry)
47
+ # If no index page is detected, move on to the next entry.
48
+ idxpth = File.join(entry, 'index.%s')
49
+ next unless FORMATS.detect {|fmt| File.exists?(idxpth % fmt)}
50
+ else
51
+ # Ignore any file that isn't a page.
52
+ next unless entry.match(/\.(#{fmts})$/)
53
+ end
54
+
55
+ entry = entry.sub("#{mpth}/", '').sub(/\.(#{fmts})/, '')
56
+ page = Page.find_by_path(entry)
57
+
58
+ # If we have a page and we haven't been asked skip
59
+ # this page, add it to the list.
60
+ if page and not page.metadata('skip subpage')
61
+ pages.push(page)
62
+ end
63
+ end
64
+
65
+ @subpages = pages.sort {|n, m| n.title.downcase <=> m.title.downcase}
66
+
67
+ return @subpages
68
+ end
69
+
70
+ # Returns true if the page is an index page AND there are
71
+ # any subpages, false otherwise.
72
+ def has_subpages?
73
+ return false unless self.index_page?
74
+ return self.subpages.empty? ? false : true
75
+ end
76
+ end
77
+
78
+ class App
79
+ helpers Nesta::Plugin::Subpages::Helpers
80
+ end
81
+ end
@@ -0,0 +1,7 @@
1
+ module Nesta
2
+ module Plugin
3
+ module Subpages
4
+ VERSION = "0.5.0"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/nesta-plugin-subpages/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Syntruth"]
6
+ gem.email = ["syntruth@gmail.com"]
7
+ gem.description = "Plugin that adds index page subpages methods and helpers"
8
+ gem.summary = "Nesta CMS Subpages Plugin."
9
+ gem.homepage = "https://github.com/syntruth/Nesta-Subpages-Plugin"
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "nesta-plugin-subpages"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Nesta::Plugin::Subpages::VERSION
17
+ gem.add_dependency("nesta", ">= 0.9.11")
18
+ gem.add_development_dependency("rake")
19
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nesta-plugin-subpages
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.5.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Syntruth
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-07-11 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: nesta
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.9.11
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 0.9.11
30
+ - !ruby/object:Gem::Dependency
31
+ name: rake
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ type: :development
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ description: Plugin that adds index page subpages methods and helpers
47
+ email:
48
+ - syntruth@gmail.com
49
+ executables: []
50
+ extensions: []
51
+ extra_rdoc_files: []
52
+ files:
53
+ - .gitignore
54
+ - Gemfile
55
+ - LICENSE
56
+ - README.md
57
+ - Rakefile
58
+ - lib/nesta-plugin-subpages.rb
59
+ - lib/nesta-plugin-subpages/init.rb
60
+ - lib/nesta-plugin-subpages/version.rb
61
+ - nesta-plugin-subpages.gemspec
62
+ homepage: https://github.com/syntruth/Nesta-Subpages-Plugin
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.23
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: Nesta CMS Subpages Plugin.
86
+ test_files: []