simple_hashtag 0.1.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.
Files changed (65) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +19 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +6 -0
  5. data/Gemfile +4 -0
  6. data/LICENSE.txt +22 -0
  7. data/README.md +174 -0
  8. data/Rakefile +6 -0
  9. data/lib/generators/simple_hashtag/migration_generator.rb +20 -0
  10. data/lib/generators/simple_hashtag/templates/migrations/create_hashtaggings_migration.rb +11 -0
  11. data/lib/generators/simple_hashtag/templates/migrations/create_hashtags_migration.rb +10 -0
  12. data/lib/generators/simple_hashtag/templates/views/hashtags_controller.rb +8 -0
  13. data/lib/generators/simple_hashtag/templates/views/hashtags_helper.rb +16 -0
  14. data/lib/generators/simple_hashtag/templates/views/hashtags_index.html.erb +8 -0
  15. data/lib/generators/simple_hashtag/views_generator.rb +14 -0
  16. data/lib/simple_hashtag/hashtag.rb +39 -0
  17. data/lib/simple_hashtag/hashtaggable.rb +45 -0
  18. data/lib/simple_hashtag/hashtagging.rb +8 -0
  19. data/lib/simple_hashtag/version.rb +3 -0
  20. data/lib/simple_hashtag.rb +6 -0
  21. data/simple_hashtag.gemspec +28 -0
  22. data/spec/dummy/README.rdoc +261 -0
  23. data/spec/dummy/Rakefile +7 -0
  24. data/spec/dummy/app/assets/javascripts/application.js +15 -0
  25. data/spec/dummy/app/assets/stylesheets/application.css +13 -0
  26. data/spec/dummy/app/controllers/application_controller.rb +3 -0
  27. data/spec/dummy/app/helpers/application_helper.rb +2 -0
  28. data/spec/dummy/app/mailers/.gitkeep +0 -0
  29. data/spec/dummy/app/models/.gitkeep +0 -0
  30. data/spec/dummy/app/models/picture.rb +4 -0
  31. data/spec/dummy/app/models/post.rb +3 -0
  32. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  33. data/spec/dummy/config/application.rb +56 -0
  34. data/spec/dummy/config/boot.rb +10 -0
  35. data/spec/dummy/config/database.yml +25 -0
  36. data/spec/dummy/config/environment.rb +5 -0
  37. data/spec/dummy/config/environments/development.rb +37 -0
  38. data/spec/dummy/config/environments/production.rb +67 -0
  39. data/spec/dummy/config/environments/test.rb +37 -0
  40. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  41. data/spec/dummy/config/initializers/inflections.rb +15 -0
  42. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  43. data/spec/dummy/config/initializers/secret_token.rb +7 -0
  44. data/spec/dummy/config/initializers/session_store.rb +8 -0
  45. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  46. data/spec/dummy/config/locales/en.yml +5 -0
  47. data/spec/dummy/config/routes.rb +2 -0
  48. data/spec/dummy/config.ru +4 -0
  49. data/spec/dummy/db/migrate/20130919041824_create_posts.rb +9 -0
  50. data/spec/dummy/db/migrate/20130919041825_create_pictures.rb +9 -0
  51. data/spec/dummy/db/migrate/20131004085836_create_simple_hashtag_hashtags.rb +9 -0
  52. data/spec/dummy/db/migrate/20131004085907_create_simple_hashtag_hashtaggings.rb +10 -0
  53. data/spec/dummy/db/schema.rb +43 -0
  54. data/spec/dummy/lib/assets/.gitkeep +0 -0
  55. data/spec/dummy/log/.gitkeep +0 -0
  56. data/spec/dummy/log/development.log +92 -0
  57. data/spec/dummy/log/test.log +3423 -0
  58. data/spec/dummy/public/404.html +26 -0
  59. data/spec/dummy/public/422.html +26 -0
  60. data/spec/dummy/public/500.html +25 -0
  61. data/spec/dummy/public/favicon.ico +0 -0
  62. data/spec/dummy/script/rails +6 -0
  63. data/spec/simple_hashtag_spec.rb +103 -0
  64. data/spec/spec_helper.rb +13 -0
  65. metadata +221 -0
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The page you were looking for doesn't exist (404)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/404.html -->
21
+ <div class="dialog">
22
+ <h1>The page you were looking for doesn't exist.</h1>
23
+ <p>You may have mistyped the address or the page may have moved.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,26 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>The change you wanted was rejected (422)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/422.html -->
21
+ <div class="dialog">
22
+ <h1>The change you wanted was rejected.</h1>
23
+ <p>Maybe you tried to change something you didn't have access to.</p>
24
+ </div>
25
+ </body>
26
+ </html>
@@ -0,0 +1,25 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title>We're sorry, but something went wrong (500)</title>
5
+ <style type="text/css">
6
+ body { background-color: #fff; color: #666; text-align: center; font-family: arial, sans-serif; }
7
+ div.dialog {
8
+ width: 25em;
9
+ padding: 0 4em;
10
+ margin: 4em auto 0 auto;
11
+ border: 1px solid #ccc;
12
+ border-right-color: #999;
13
+ border-bottom-color: #999;
14
+ }
15
+ h1 { font-size: 100%; color: #f00; line-height: 1.5em; }
16
+ </style>
17
+ </head>
18
+
19
+ <body>
20
+ <!-- This file lives in public/500.html -->
21
+ <div class="dialog">
22
+ <h1>We're sorry, but something went wrong.</h1>
23
+ </div>
24
+ </body>
25
+ </html>
File without changes
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ APP_PATH = File.expand_path('../../config/application', __FILE__)
5
+ require File.expand_path('../../config/boot', __FILE__)
6
+ require 'rails/commands'
@@ -0,0 +1,103 @@
1
+ require 'spec_helper'
2
+
3
+ describe SimpleHashtag do
4
+
5
+ describe ".hashtag" do
6
+ context "regex" do
7
+ it "match valid hashtags" do
8
+ text = "It's a dangerous business, #Frodo, going out your door."
9
+ text += "You step onto #the-road,"
10
+ text += "and if you don't keep #your_feet,"
11
+ text += "there's no #know1ng where you might be swept off to."
12
+ match = Post.new().scan_for_hashtags(text)
13
+ match.should eq [["#Frodo", "Frodo"], ["#the-road", "the-road"], ["#your_feet", "your_feet"], ["#know1ng", "know1ng"]]
14
+ end
15
+
16
+ it "doesn't match things that look like hashtags but are not" do
17
+ text = "And some things that should not # have been forgotten were lost."
18
+ text += "History became legend#. Legend became myth."
19
+ text += "And for two and a half t#ousand years, the ring passed out of all knowledge."
20
+ match = Post.new().scan_for_hashtags(text)
21
+ match.should eq []
22
+ end
23
+ end
24
+
25
+ it "returns a string when asked to" do
26
+ tag = SimpleHashtag::Hashtag.new(name: "RubyRocks")
27
+ tag.to_s.should eq "rubyrocks"
28
+ tag.to_s.should be_a(String)
29
+ end
30
+
31
+ it "downcase a parsed tag" do
32
+ tag = SimpleHashtag::Hashtag.new(name: "WEirDcasE")
33
+ tag.name.should eq "weirdcase"
34
+ end
35
+
36
+ it "finds a mis-cased tag" do
37
+ SimpleHashtag::Hashtag.connection.execute("INSERT INTO simple_hashtag_hashtags (name) values ('WEirDcasE')")
38
+ tag = SimpleHashtag::Hashtag.find_by_name("WEIRDCASE")
39
+ tag.should_not eq nil
40
+ tag.should be_a(SimpleHashtag::Hashtag)
41
+ tag.name.should eq "weirdcase"
42
+ end
43
+
44
+ it "knows about its hashtaggables" do
45
+ Post.create(body: "I thought up an ending for my #book.")
46
+ Picture.create(caption: "Some who have read the #book.")
47
+
48
+ tag = SimpleHashtag::Hashtag.find_by_name("book")
49
+ tag.hashtaggables.size.should eq 2
50
+ tag.hashtaggables.first.body.should eq "I thought up an ending for my #book."
51
+ tag.hashtaggables.last.caption.should eq "Some who have read the #book."
52
+ end
53
+
54
+ it "can clean the DB from orphan tags" do
55
+ Post.create(body: "Certainty of death, small #chance of success.")
56
+ p = Post.last
57
+ p.body = "What are we #waiting for?"
58
+ p.save
59
+ SimpleHashtag::Hashtag.clean_orphans
60
+
61
+ SimpleHashtag::Hashtag.all.map(&:name).should_not include "chance"
62
+ end
63
+ end
64
+
65
+ describe ".hashtaggable" do
66
+ it "store a hashtag" do
67
+ Post.create(body: "Don't go where I can't #follow.")
68
+ p = Post.last
69
+ p.hashtags.count.should eq 1
70
+ p.hashtags.last.name.should eq "follow"
71
+ end
72
+
73
+ it "reflect a change" do
74
+ Post.create(body: "Certainty of death, small #chance of success.")
75
+ p = Post.last
76
+ p.body += "What are we #waiting for?"
77
+ p.save
78
+
79
+ p.hashtags.count.should eq 2
80
+ p.hashtags.last.name.should eq "waiting"
81
+ end
82
+
83
+ it "can have an empty attribute" do
84
+ Post.create()
85
+ end
86
+
87
+ it "can have multiple hashtags" do
88
+ Post.create(body: "The grey #rain-curtain of this world rolls back, and all turns to #silver glass, and then you #see it.")
89
+ p = Post.last
90
+
91
+ p.hashtags.count.should eq 3
92
+ p.hashtags.map(&:to_s).should eq ["rain-curtain", "silver", "see"]
93
+ end
94
+
95
+ it "handles a model with custom attribute" do
96
+ Picture.create(caption: "The grey #rain-curtain of this world rolls back, and all turns to #silver glass, and then you #see it.")
97
+ p = Picture.last
98
+
99
+ p.hashtags.count.should eq 3
100
+ p.hashtags.map(&:to_s).should eq ["rain-curtain", "silver", "see"]
101
+ end
102
+ end
103
+ end
@@ -0,0 +1,13 @@
1
+ ENV["RAILS_ENV"] = "test"
2
+
3
+ require File.expand_path("../dummy/config/environment.rb", __FILE__)
4
+ require 'rspec/rails'
5
+ require "rails/test_help"
6
+ require 'simple_hashtag'
7
+
8
+ RSpec.configure do |config|
9
+ config.use_transactional_fixtures = true
10
+ config.after :all do
11
+ ActiveRecord::Base.subclasses.each(&:delete_all)
12
+ end
13
+ end
metadata ADDED
@@ -0,0 +1,221 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: simple_hashtag
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Raphael Campardou
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-10-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rails
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>'
18
+ - !ruby/object:Gem::Version
19
+ version: 3.2.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>'
25
+ - !ruby/object:Gem::Version
26
+ version: 3.2.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bundler
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: '1.3'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '1.3'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rake
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - '>='
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - '>='
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rspec-rails
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - '>='
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: sqlite3
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - '>='
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ description: Parse, store retreive and format hashtags in your text.
84
+ email:
85
+ - ralovely@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - .gitignore
91
+ - .rspec
92
+ - .travis.yml
93
+ - Gemfile
94
+ - LICENSE.txt
95
+ - README.md
96
+ - Rakefile
97
+ - lib/generators/simple_hashtag/migration_generator.rb
98
+ - lib/generators/simple_hashtag/templates/migrations/create_hashtaggings_migration.rb
99
+ - lib/generators/simple_hashtag/templates/migrations/create_hashtags_migration.rb
100
+ - lib/generators/simple_hashtag/templates/views/hashtags_controller.rb
101
+ - lib/generators/simple_hashtag/templates/views/hashtags_helper.rb
102
+ - lib/generators/simple_hashtag/templates/views/hashtags_index.html.erb
103
+ - lib/generators/simple_hashtag/views_generator.rb
104
+ - lib/simple_hashtag.rb
105
+ - lib/simple_hashtag/hashtag.rb
106
+ - lib/simple_hashtag/hashtaggable.rb
107
+ - lib/simple_hashtag/hashtagging.rb
108
+ - lib/simple_hashtag/version.rb
109
+ - simple_hashtag.gemspec
110
+ - spec/dummy/README.rdoc
111
+ - spec/dummy/Rakefile
112
+ - spec/dummy/app/assets/javascripts/application.js
113
+ - spec/dummy/app/assets/stylesheets/application.css
114
+ - spec/dummy/app/controllers/application_controller.rb
115
+ - spec/dummy/app/helpers/application_helper.rb
116
+ - spec/dummy/app/mailers/.gitkeep
117
+ - spec/dummy/app/models/.gitkeep
118
+ - spec/dummy/app/models/picture.rb
119
+ - spec/dummy/app/models/post.rb
120
+ - spec/dummy/app/views/layouts/application.html.erb
121
+ - spec/dummy/config.ru
122
+ - spec/dummy/config/application.rb
123
+ - spec/dummy/config/boot.rb
124
+ - spec/dummy/config/database.yml
125
+ - spec/dummy/config/environment.rb
126
+ - spec/dummy/config/environments/development.rb
127
+ - spec/dummy/config/environments/production.rb
128
+ - spec/dummy/config/environments/test.rb
129
+ - spec/dummy/config/initializers/backtrace_silencers.rb
130
+ - spec/dummy/config/initializers/inflections.rb
131
+ - spec/dummy/config/initializers/mime_types.rb
132
+ - spec/dummy/config/initializers/secret_token.rb
133
+ - spec/dummy/config/initializers/session_store.rb
134
+ - spec/dummy/config/initializers/wrap_parameters.rb
135
+ - spec/dummy/config/locales/en.yml
136
+ - spec/dummy/config/routes.rb
137
+ - spec/dummy/db/migrate/20130919041824_create_posts.rb
138
+ - spec/dummy/db/migrate/20130919041825_create_pictures.rb
139
+ - spec/dummy/db/migrate/20131004085836_create_simple_hashtag_hashtags.rb
140
+ - spec/dummy/db/migrate/20131004085907_create_simple_hashtag_hashtaggings.rb
141
+ - spec/dummy/db/schema.rb
142
+ - spec/dummy/lib/assets/.gitkeep
143
+ - spec/dummy/log/.gitkeep
144
+ - spec/dummy/log/development.log
145
+ - spec/dummy/log/test.log
146
+ - spec/dummy/public/404.html
147
+ - spec/dummy/public/422.html
148
+ - spec/dummy/public/500.html
149
+ - spec/dummy/public/favicon.ico
150
+ - spec/dummy/script/rails
151
+ - spec/simple_hashtag_spec.rb
152
+ - spec/spec_helper.rb
153
+ homepage: https://github.com/ralovely/simple_hashtag
154
+ licenses:
155
+ - MIT
156
+ metadata: {}
157
+ post_install_message:
158
+ rdoc_options: []
159
+ require_paths:
160
+ - lib
161
+ required_ruby_version: !ruby/object:Gem::Requirement
162
+ requirements:
163
+ - - '>='
164
+ - !ruby/object:Gem::Version
165
+ version: 1.9.3
166
+ required_rubygems_version: !ruby/object:Gem::Requirement
167
+ requirements:
168
+ - - '>='
169
+ - !ruby/object:Gem::Version
170
+ version: '0'
171
+ requirements: []
172
+ rubyforge_project:
173
+ rubygems_version: 2.1.5
174
+ signing_key:
175
+ specification_version: 4
176
+ summary: Simple Hashtag is a mix between–well–hashtags as we know them and categories.
177
+ It will scan your Active Record attribute for a tag and store it in an index.
178
+ test_files:
179
+ - spec/dummy/README.rdoc
180
+ - spec/dummy/Rakefile
181
+ - spec/dummy/app/assets/javascripts/application.js
182
+ - spec/dummy/app/assets/stylesheets/application.css
183
+ - spec/dummy/app/controllers/application_controller.rb
184
+ - spec/dummy/app/helpers/application_helper.rb
185
+ - spec/dummy/app/mailers/.gitkeep
186
+ - spec/dummy/app/models/.gitkeep
187
+ - spec/dummy/app/models/picture.rb
188
+ - spec/dummy/app/models/post.rb
189
+ - spec/dummy/app/views/layouts/application.html.erb
190
+ - spec/dummy/config.ru
191
+ - spec/dummy/config/application.rb
192
+ - spec/dummy/config/boot.rb
193
+ - spec/dummy/config/database.yml
194
+ - spec/dummy/config/environment.rb
195
+ - spec/dummy/config/environments/development.rb
196
+ - spec/dummy/config/environments/production.rb
197
+ - spec/dummy/config/environments/test.rb
198
+ - spec/dummy/config/initializers/backtrace_silencers.rb
199
+ - spec/dummy/config/initializers/inflections.rb
200
+ - spec/dummy/config/initializers/mime_types.rb
201
+ - spec/dummy/config/initializers/secret_token.rb
202
+ - spec/dummy/config/initializers/session_store.rb
203
+ - spec/dummy/config/initializers/wrap_parameters.rb
204
+ - spec/dummy/config/locales/en.yml
205
+ - spec/dummy/config/routes.rb
206
+ - spec/dummy/db/migrate/20130919041824_create_posts.rb
207
+ - spec/dummy/db/migrate/20130919041825_create_pictures.rb
208
+ - spec/dummy/db/migrate/20131004085836_create_simple_hashtag_hashtags.rb
209
+ - spec/dummy/db/migrate/20131004085907_create_simple_hashtag_hashtaggings.rb
210
+ - spec/dummy/db/schema.rb
211
+ - spec/dummy/lib/assets/.gitkeep
212
+ - spec/dummy/log/.gitkeep
213
+ - spec/dummy/log/development.log
214
+ - spec/dummy/log/test.log
215
+ - spec/dummy/public/404.html
216
+ - spec/dummy/public/422.html
217
+ - spec/dummy/public/500.html
218
+ - spec/dummy/public/favicon.ico
219
+ - spec/dummy/script/rails
220
+ - spec/simple_hashtag_spec.rb
221
+ - spec/spec_helper.rb