governor_tags 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: ./
3
3
  specs:
4
- governor_tags (0.1.1)
4
+ governor_tags (0.2.0)
5
5
  governor (>= 0.5.2)
6
6
  rails (~> 3.0.5)
7
7
 
data/README.rdoc CHANGED
@@ -31,7 +31,23 @@ add tags to. This will create a Tag class and associated migration.
31
31
  == Usage
32
32
 
33
33
  Now, when you modify an article, you'll see places to add tags right in the
34
- page. You really don't have to do anything special at this point.
34
+ page.
35
+
36
+ If you'd like to display a list of tags with links to each tag as a helper
37
+ (maybe as part of a sidebar), you can call the following helper:
38
+
39
+ <%= tag_list @your_tags %>
40
+
41
+ where <code>@your_tags</code> is an array of tags.
42
+
43
+ Also, if you'd like to have a JSON-searchable list of tags, perhaps for use
44
+ with an autocomplete feature, you can pass your query on to
45
+ <code>/:resources/tags/query</code>, where <code>:resources</code> corresponds
46
+ to the resource type you chose above. If you're using the default Governor
47
+ resource type, this would be <code>/articles/tags/query</code>. Here's a
48
+ snippet, if you're using jQuery:
49
+
50
+ $.getJSON("/articles/tags/query", {query: request.term.split(/,\s*/).pop()}, response);
35
51
 
36
52
  == Contributing to governor_tags
37
53
 
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.2.0
@@ -5,11 +5,18 @@ module Governor
5
5
  helper :governor
6
6
  helper Governor::Controllers::Helpers
7
7
 
8
+ respond_to :json, :only => :query
9
+
8
10
  def show
9
11
  @tag = Tag.find(params[:id], :include => :resources)
10
12
  set_resources @tag.resources
11
13
  flash[:notice] = t('governor_tags.tags_for', :resource_type => params[:governor_mapping], :tag => @tag.name)
12
14
  render :template => 'governor/articles/index'
13
15
  end
16
+
17
+ def query
18
+ tags = Tag.all(:conditions => ['name like ?', "#{params[:query]}%"])
19
+ respond_with tags.map{|tag| tag.name }
20
+ end
14
21
  end
15
22
  end
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{governor_tags}
8
- s.version = "0.1.1"
8
+ s.version = "0.2.0"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Liam Morley"]
data/lib/governor_tags.rb CHANGED
@@ -5,7 +5,11 @@ tags = Governor::Plugin.new('tags')
5
5
 
6
6
  tags.set_routes do
7
7
  collection do
8
- resources :tags, :only => :show, :module => :governor
8
+ resources :tags, :only => :show, :module => :governor do
9
+ collection do
10
+ get :query
11
+ end
12
+ end
9
13
  end
10
14
  end
11
15
  tags.register_model_callback do |base|
@@ -17,5 +17,17 @@ module Governor
17
17
  response.body.should include html_escape('Showing articles tagged as "misconduct".')
18
18
  end
19
19
  end
20
+
21
+ context "#query" do
22
+ it "responds with a list of tags beginning with the input" do
23
+ get :query, :query => 'misc', :governor_mapping => :articles, :format => :json
24
+ response.body.should == ['misconduct'].to_json
25
+ end
26
+
27
+ it "responds with an empty array if there are no matches" do
28
+ get :query, :query => 'not a match', :governor_mapping => :articles, :format => :json
29
+ response.body.should == [].to_json
30
+ end
31
+ end
20
32
  end
21
33
  end
@@ -8,7 +8,7 @@ GIT
8
8
  PATH
9
9
  remote: ../..
10
10
  specs:
11
- governor_tags (0.1.1)
11
+ governor_tags (0.2.0)
12
12
  governor (>= 0.5.2)
13
13
  rails (~> 3.0.5)
14
14
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: governor_tags
3
3
  version: !ruby/object:Gem::Version
4
- hash: 25
4
+ hash: 23
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
- - 1
9
- - 1
10
- version: 0.1.1
8
+ - 2
9
+ - 0
10
+ version: 0.2.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Liam Morley