nesta-plugin-taggr 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2a335bab9b637d404c7bce30e7d452435c1f866b
4
+ data.tar.gz: 0b016e8ba799d52327cc2911ad6249c2824bce84
5
+ SHA512:
6
+ metadata.gz: 26f6cbd6cb8689249424c152219ba222cdbc26dbe49d330cf5ace1377f006b54095ee7ea798b76c1a5382e2b0d1828d8a989ac3a40f0a8198ef85b3b43121e97
7
+ data.tar.gz: 2a97554587957d03eb19aca297c60894cae0975243faa92916fbefa904c010c843573da01df4cf4cd418bf91d29eba8b097d61a786ce02ed8c4cff7cc2e58f30
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ pkg/*
2
+ *.gem
3
+ .bundle
4
+ vendor/bundle
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in nesta-search.gemspec
4
+ gemspec
data/Gemfile.lock ADDED
@@ -0,0 +1,14 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ nesta-plugin-taggr (0.0.1)
5
+
6
+ GEM
7
+ remote: http://rubygems.org/
8
+ specs:
9
+
10
+ PLATFORMS
11
+ ruby
12
+
13
+ DEPENDENCIES
14
+ nesta-plugin-taggr!
data/README.md ADDED
@@ -0,0 +1,65 @@
1
+ README
2
+ ======
3
+
4
+ nesta-plugin-taggr is a plugin for the Nesta CMS to support 'tags' metadata
5
+
6
+ Installation
7
+ ------------
8
+
9
+ To install it as a gem add `nesta-plugin-taggr` to the `Gemfile` in your Nesta
10
+ project, and then re-run `bundle`:
11
+
12
+ gem 'nesta-plugin-taggr', git: "git://github.com/dansunotori/nesta-plugin-taggr.git"
13
+
14
+ Usage examples
15
+ --------------
16
+
17
+ My page has tags!
18
+
19
+ - unless @page.tags.empty?
20
+ - @page.tags.each do |tag|
21
+ %a.btn.btn-info.btn-xs{ :href => "/tag?q=#{tag}", role: 'button' }= tag
22
+
23
+ Tag cloud buttons with Bootstrap. `tag_cloud` returns an array of `[tag, global_count]` pairs sorted by tag alphabetically.
24
+
25
+ .panel
26
+ - min_weight = 0
27
+ - btn_class = [ 'btn-xs', 'btn-sm', '', 'btn-lg' ]
28
+ - cloud = tag_cloud.select { |k,v| v > min_weight }
29
+ - max_weight = cloud.max_by{|k,v| v}[1] - min_weight
30
+ - cloud.each do |key, value|
31
+ - weight = ((value * 1.0 / max_weight) * 4).ceil - 1
32
+ %a{ :class => "tagcloud btn btn-info #{btn_class[weight]}", href: "/tag?q=#{key}", role: 'button' }= key
33
+
34
+ Similar articles are sorted by relevance in descending order; similarity is a number of common tags.
35
+
36
+ %ul.list-group
37
+ - @page.similar_articles_by_tags.first(3).each do |article, similarity|
38
+ %li.list-group-item
39
+ %a{ :href => article.abspath }= article.heading
40
+
41
+ To search for a tag create `/content/pages/tag.haml`. For safety in this example I'm not displaying a tag if it's not found.
42
+
43
+ - if (results = pages_by_tag( params[:q] )) && !results.empty?
44
+ %h1 Pages tagged '#{params[:q]}'
45
+ %section.articles= article_summaries(results)
46
+ - else
47
+ %h1 Oops!
48
+ %h3 Looks like there's no such tag.
49
+
50
+ Configuration
51
+ -------------
52
+
53
+ None so far
54
+
55
+ Usage Notes
56
+ -----------
57
+ Tags are down-cased.
58
+
59
+ If you're using `nesta-plugin-search` you'll need to add your `/tag` page to ignore list in `config.yaml`.
60
+
61
+ search_ignore_list:
62
+ - /
63
+ - /tag
64
+
65
+
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,70 @@
1
+ module Nesta
2
+ # module Plugin
3
+ # module Taggr
4
+ # module Helpers
5
+ # If your plugin needs any helper methods,
6
+ # add them here...
7
+ # end
8
+ # end
9
+ # end
10
+
11
+ class App
12
+ # helpers Nesta::Plugin::Taggr::Helpers
13
+ helpers do
14
+ def tag_cloud
15
+ $tag_cloud ||= Nesta::Page.tag_cloud
16
+ end
17
+
18
+ def pages_by_tag(tag)
19
+ Nesta::Page.pages_by_tag(tag)
20
+ end
21
+ end
22
+ end
23
+
24
+ class Page
25
+ @@tag_cloud = {}
26
+
27
+ # return hash of tags
28
+ def self.tag_cloud
29
+ @@tag_cloud = init_tag_cloud() if @@tag_cloud.nil? || @@tag_cloud.empty?
30
+ end
31
+
32
+ def self.pages_by_tag(tag)
33
+ Page.find_all.select { |page| page.tags.include?( tag ) }.sort { |x, y| y.date <=> x.date } unless tag.nil? || tag.empty?
34
+ end
35
+
36
+ def tags
37
+ tag_strings
38
+ end
39
+
40
+ def similar_pages_by_tags
41
+ similar_pages = Hash.new(0)
42
+ Page.find_all.each do |page|
43
+ similar_pages[page] = (self.tags & page.tags).size unless page == self
44
+ end
45
+ similar_pages.reject { |page, similarity| similarity == 0 }.sort_by { |page, similarity| similarity }.reverse
46
+ end
47
+
48
+ def similar_articles_by_tags
49
+ similar_articles = Hash.new(0)
50
+ Page.find_articles.each do |page|
51
+ similar_articles[page] = (self.tags & page.tags).size unless page == self
52
+ end
53
+ similar_articles.reject { |page, similarity| similarity == 0 }.sort_by { |page, similarity| similarity }.reverse
54
+ end
55
+
56
+ private
57
+ def self.init_tag_cloud
58
+ cloud = Hash.new(0)
59
+ Page.find_all.each do |page|
60
+ page.tags.each { |t| cloud[t] += 1 }
61
+ end
62
+ cloud.sort
63
+ end
64
+
65
+ def tag_strings
66
+ strings = metadata('tags')
67
+ strings.nil? ? [] : strings.split(',').map { |string| string.strip.downcase }.reject { |s| s.empty? }
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,7 @@
1
+ module Nesta
2
+ module Plugin
3
+ module Taggr
4
+ VERSION = "0.0.2"
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ require "nesta-plugin-search/version"
2
+
3
+ Nesta::Plugin.register(__FILE__)
@@ -0,0 +1,20 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "nesta-plugin-taggr/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "nesta-plugin-taggr"
7
+ s.version = Nesta::Plugin::Taggr::VERSION
8
+ s.platform = Gem::Platform::RUBY
9
+ s.authors = ["Alexander Golev"]
10
+ s.email = ["sasha.golev@gmail.com"]
11
+ s.licenses = ['MIT']
12
+ s.homepage = "http://github.com/dansunotori/search-plugin-taggr"
13
+ s.summary = %q{Tag support plugin for Nesta CMS}
14
+ s.description = %q{Adds support for 'tags' metadata.}
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+ end
metadata ADDED
@@ -0,0 +1,53 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: nesta-plugin-taggr
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Alexander Golev
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-03-06 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: Adds support for 'tags' metadata.
14
+ email:
15
+ - sasha.golev@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - .gitignore
21
+ - Gemfile
22
+ - Gemfile.lock
23
+ - README.md
24
+ - Rakefile
25
+ - lib/nesta-plugin-taggr.rb
26
+ - lib/nesta-plugin-taggr/init.rb
27
+ - lib/nesta-plugin-taggr/version.rb
28
+ - nesta-plugin-taggr.gemspec
29
+ homepage: http://github.com/dansunotori/search-plugin-taggr
30
+ licenses:
31
+ - MIT
32
+ metadata: {}
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - '>='
40
+ - !ruby/object:Gem::Version
41
+ version: '0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '>='
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubyforge_project:
49
+ rubygems_version: 2.2.2
50
+ signing_key:
51
+ specification_version: 4
52
+ summary: Tag support plugin for Nesta CMS
53
+ test_files: []