Skip to content

Commit 4c07e55

Browse files
committed
initial commit
0 parents  commit 4c07e55

14 files changed

+277
-0
lines changed

.gitignore

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/.bundle/
2+
/.yardoc
3+
/Gemfile.lock
4+
/_yardoc/
5+
/coverage/
6+
/doc/
7+
/pkg/
8+
/spec/reports/
9+
/tmp/

.travis.yml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
sudo: false
2+
language: ruby
3+
script: 'bundle exec rake'
4+
rvm:
5+
- 2.2.5
6+
before_install:
7+
- gem install bundler -v 1.12.5
8+
notifications:
9+
email:
10+
recipients:
11+
12+
on_failure: change
13+
on_success: never

Gemfile

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
source 'https://rubygems.org'
2+
3+
# Specify your gem's dependencies in hashtags.gemspec
4+
gemspec

Guardfile

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
guard :minitest do
2+
watch(%r{^lib/(.+)\.rb$}) { |m| "test/#{m[1]}_test.rb" }
3+
watch(%r{^test/.+_test\.rb$})
4+
watch(%r{^test/test_helper\.rb$}) { 'test' }
5+
end

LICENSE.txt

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
The MIT License (MIT)
2+
3+
Copyright (c) 2016 Tomas Celizna
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in
13+
all copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
THE SOFTWARE.

README.md

+150
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
# Hashtags
2+
3+
[![Build Status](https://travis-ci.org/tomasc/hashtags.svg)](https://travis-ci.org/tomasc/hashtags) [![Gem Version](https://badge.fury.io/rb/hashtags.svg)](http://badge.fury.io/rb/hashtags) [![Coverage Status](https://img.shields.io/coveralls/tomasc/hashtags.svg)](https://coveralls.io/r/tomasc/hashtags)
4+
5+
Set of models and JS plugins to facilitate inline text hashtags.
6+
7+
* hashtags are entered inline in text, for example as `@tomasc`, `#location:Home(12345)` or `$my_variable`
8+
* when rendered, they are replaced by actual values, for example HTML tags, images, links etc.
9+
10+
Additionally:
11+
12+
* the user can be assisted with a dropdown triggered by a special character (`#`, `@`, `$`, …)
13+
* `has_hash_tag_field` method is available to assist when rendering HTML input fields incl. data attributes, help, and supporting only specified hashtag classes
14+
* hashtags typically have `cache_key` defined on class so corresponding fragment cache can be easily expired
15+
16+
## Installation
17+
18+
Add this line to your application's Gemfile:
19+
20+
```ruby
21+
gem 'hashtags'
22+
```
23+
24+
And then execute:
25+
26+
$ bundle
27+
28+
Or install it yourself as:
29+
30+
$ gem install hashtags
31+
32+
## Usage
33+
34+
The hashtags have the following structure:
35+
36+
```
37+
<trigger>(type)(human_id)<value>
38+
```
39+
40+
The three following types are included in this gem, however the gem's design allows for definition of new types and their subclassing.
41+
42+
### Hash tag types
43+
44+
#### User hash tag
45+
46+
```
47+
@tomasc
48+
```
49+
50+
#### Resource hash tag
51+
52+
```
53+
#location:Home(12345)
54+
```
55+
56+
#### Variable hash tag
57+
58+
```
59+
$number_of_users
60+
```
61+
62+
### Adding new hash tags in your application
63+
64+
The following are quick examples. It is advised to read the source code of `Hashtags::User`, `Hashtags::Resource` and `Hashtags::Variable` and their superclass `Hashtags::Builder` in order to fully understand the possibilities and flexibility of this gem.
65+
66+
#### User
67+
68+
See `Hashtags::User` and override its methods on your subclass as necessary. Typically it would be at least the following:
69+
70+
```ruby
71+
class UserTag < Hashtags::User
72+
def self.resource_class
73+
# User
74+
end
75+
76+
def self.resources_for_query(query)
77+
# User.where(full_name: /#{query}/i)
78+
end
79+
80+
def resource_as_json(resource)
81+
# {
82+
# _id: resource.id.to_s,
83+
# to_s: resource.full_name,
84+
# human_id: resource.full_name
85+
# }
86+
end
87+
end
88+
```
89+
90+
#### Resource
91+
92+
See `Hashtags::Resource` and override its methods on your subclass as necessary. Typically it would be at least the following:
93+
94+
```ruby
95+
class LocationTag < Hashtags::Resource
96+
def self.resource_class
97+
# Location
98+
end
99+
100+
def self.resources_for_query(query)
101+
# Location.where(name: /#{query}/i)
102+
end
103+
104+
def resource_as_json(resource)
105+
# {
106+
# _id: resource.id.to_s,
107+
# to_s: resource.name,
108+
# human_id: resource.name
109+
# }
110+
end
111+
end
112+
```
113+
114+
#### Variable
115+
116+
See `Hashtags::Variable` and override its methods on your subclass as necessary. Typically it would be at least the following:
117+
118+
```ruby
119+
class LocationTag < Hashtags::Resource
120+
def self.values(_hash_tag_classes)
121+
# %w(
122+
# variable_1
123+
# variable_2
124+
# )
125+
end
126+
127+
def markup(match)
128+
# case name(match)
129+
# when 'variable_1' then get_value_of_variable_1(match)
130+
# when 'variable_2' then get_value_of_variable_2(match)
131+
# end
132+
end
133+
end
134+
```
135+
136+
137+
## Development
138+
139+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
140+
141+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
142+
143+
## Contributing
144+
145+
Bug reports and pull requests are welcome on GitHub at https://github.com/tomasc/hashtags.
146+
147+
148+
## License
149+
150+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).

Rakefile

+10
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
require "bundler/gem_tasks"
2+
require "rake/testtask"
3+
4+
Rake::TestTask.new(:test) do |t|
5+
t.libs << "test"
6+
t.libs << "lib"
7+
t.test_files = FileList['test/**/*_test.rb']
8+
end
9+
10+
task :default => :test

bin/console

+14
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
#!/usr/bin/env ruby
2+
3+
require "bundler/setup"
4+
require "hashtags"
5+
6+
# You can add fixtures and/or initialization code here to make experimenting
7+
# with your gem easier. You can also use a different console, if you like.
8+
9+
# (If you use this, don't forget to add pry to your Gemfile!)
10+
# require "pry"
11+
# Pry.start
12+
13+
require "irb"
14+
IRB.start

bin/setup

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#!/usr/bin/env bash
2+
set -euo pipefail
3+
IFS=$'\n\t'
4+
set -vx
5+
6+
bundle install
7+
8+
# Do any other automated setup that you need to do here

hashtags.gemspec

+26
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# coding: utf-8
2+
lib = File.expand_path('../lib', __FILE__)
3+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4+
require 'hashtags/version'
5+
6+
Gem::Specification.new do |spec|
7+
spec.name = 'hashtags'
8+
spec.version = Hashtags::VERSION
9+
spec.authors = ['Tomas Celizna']
10+
spec.email = ['[email protected]']
11+
12+
spec.summary = 'Set of models and JS plugins to facilitate inline text hashtags.'
13+
spec.homepage = 'https://github.com/tomasc/hashtags'
14+
spec.license = 'MIT'
15+
16+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17+
spec.bindir = 'exe'
18+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
19+
spec.require_paths = ['lib']
20+
21+
spec.add_development_dependency 'bundler', '~> 1.12'
22+
spec.add_development_dependency 'guard'
23+
spec.add_development_dependency 'guard-minitest'
24+
spec.add_development_dependency 'rake', '~> 10.0'
25+
spec.add_development_dependency 'minitest', '~> 5.0'
26+
end

lib/hashtags.rb

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
require "hashtags/version"
2+
3+
module Hashtags
4+
# Your code goes here...
5+
end

lib/hashtags/version.rb

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
module Hashtags
2+
VERSION = '0.1.0'.freeze
3+
end

test/support/.gitkeep

Whitespace-only changes.

test/test_helper.rb

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
require 'bundler/setup'
2+
3+
require 'minitest'
4+
require 'minitest/autorun'
5+
require 'minitest/spec'
6+
7+
require 'hashtags'
8+
9+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each { |f| require f }

0 commit comments

Comments
 (0)