thredded-bbcode 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 3145e95e77d704dcc85d43d13be49ed8bab2d936
4
+ data.tar.gz: 242d32134d17e1ddbaf9b905a5fd75a01020bd43
5
+ SHA512:
6
+ metadata.gz: 306923468e770aca7df522cf0d7ed961877f475ca9adeca4a9a255457760ee229881300b6470fb00eacc389194528bb67dda50d99ed9ef4a1cf9f4ff8267b61a
7
+ data.tar.gz: adca123d042b4f176c9d70d526fb22dac24535ab7cc256ac5ddcb62cad29564ec1a1daeeb4893044399942447344b7301fac781d57aa1a6d0f1d17ac41219518
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016 Gleb Mazovetskiy
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.
@@ -0,0 +1,45 @@
1
+ # Thredded Plugin: BBCode [![Build Status](https://travis-ci.org/thredded/thredded-bbcode.svg?branch=master)](https://travis-ci.org/thredded/thredded-bbcode) [![Test Coverage](https://codeclimate.com/github/thredded/thredded-bbcode/badges/coverage.svg)](https://codeclimate.com/github/thredded/thredded-bbcode/coverage)
2
+
3
+ A Thredded plugin that processes your Thredded posts with BBCode via
4
+ [BBCoder](https://github.com/asceth/bbcoder).
5
+
6
+ ## Installation
7
+
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'thredded-bbcode'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ ```bash
17
+ bundle
18
+ ```
19
+
20
+ ## Usage
21
+
22
+ \-
23
+
24
+ ## Development
25
+
26
+ After checking out the repo, run `bin/setup` to install dependencies.
27
+ Then, run `rake spec` to run the tests. You can also run `bin/console` for an
28
+ interactive prompt that will allow you to experiment.
29
+
30
+ To install this gem onto your local machine, run `bundle exec rake install`.
31
+ To release a new version, update the version number in `version.rb`, and then
32
+ run `bundle exec rake release`, which will create a git tag for the version,
33
+ push git commits and tags, and push the `.gem` file to
34
+ [rubygems.org](https://rubygems.org).
35
+
36
+ ## Contributing
37
+
38
+ Bug reports and pull requests are welcome on GitHub at https://github.com/thredded/thredded-bbcode. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
39
+
40
+
41
+ ## License
42
+
43
+ The gem is available as open source under the terms of the
44
+ [MIT License](http://opensource.org/licenses/MIT).
45
+
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+ require 'thredded/bbcode/version'
3
+ require 'thredded/bbcode/railtie' if defined?(Rails)
4
+ require 'thredded/bbcode/filter'
5
+
6
+ module Thredded
7
+ module BBCode
8
+ class << self
9
+ attr_accessor :options
10
+
11
+ def setup!
12
+ Thredded::ContentFormatter.markup_filters.unshift(
13
+ Thredded::BBCode::Filter
14
+ )
15
+ BBCoder.configure do
16
+ tag :img, match: %r{^https?://.*(png|bmp|jpe?g|gif)$},
17
+ singular: false do
18
+ %(<img src="#{singular? ? meta : content}" />)
19
+ end
20
+
21
+ tag :spoilers do
22
+ %(<span class="thredded--post--content--spoiler">#{content}</span>)
23
+ end
24
+
25
+ tag :spoiler do
26
+ %(<span class="thredded--post--content--spoiler">#{content}</span>)
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ require 'bbcoder'
3
+ require 'html/pipeline/filter'
4
+ require 'html/pipeline/text_filter'
5
+
6
+ module Thredded
7
+ module BBCode
8
+ class Filter < ::HTML::Pipeline::TextFilter
9
+ def initialize(text, context = {}, result = nil)
10
+ super text, context, result
11
+ end
12
+
13
+ def call
14
+ html = BBCoder.new(@text).to_html
15
+ remove_url_link_contents! html
16
+ html.rstrip!
17
+ html
18
+ end
19
+
20
+ # <a href="http://example.com">http://example.com</a> =>
21
+ # <a href="http://example.com">example.com</a>
22
+ def remove_url_link_contents!(html)
23
+ # The doc is not fully HTML yet (it will still be parsed with markdown),
24
+ # so we can't use Nokogiri to process it here.
25
+ html.gsub!(%r{(<a href="[^"]*"[^>]*>)https?://(.*?</a>)}m, '\1\2')
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,10 @@
1
+ # frozen_string_literal: true
2
+ module Thredded
3
+ module BBCode
4
+ class Railtie < Rails::Railtie
5
+ initializer 'thredded.bbcode', after: 'thredded' do
6
+ Thredded::BBCode.setup!
7
+ end
8
+ end
9
+ end
10
+ end
@@ -0,0 +1,6 @@
1
+ # frozen_string_literal: true
2
+ module Thredded
3
+ module BBCode
4
+ VERSION = '0.1.0'
5
+ end
6
+ end
metadata ADDED
@@ -0,0 +1,120 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: thredded-bbcode
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Gleb Mazovetskiy
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-11-13 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bbcoder
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rubocop
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.45'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.45'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: simplecov
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: thredded
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: 0.8.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.8.0
83
+ description: Adds basic BBCode support to Thredded via the bbcoder gem.
84
+ email:
85
+ - glex.spb@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - LICENSE.txt
91
+ - README.md
92
+ - lib/thredded/bbcode.rb
93
+ - lib/thredded/bbcode/filter.rb
94
+ - lib/thredded/bbcode/railtie.rb
95
+ - lib/thredded/bbcode/version.rb
96
+ homepage: https://github.com/thredded/thredded-bbcode
97
+ licenses:
98
+ - MIT
99
+ metadata: {}
100
+ post_install_message:
101
+ rdoc_options: []
102
+ require_paths:
103
+ - lib
104
+ required_ruby_version: !ruby/object:Gem::Requirement
105
+ requirements:
106
+ - - "~>"
107
+ - !ruby/object:Gem::Version
108
+ version: '2.3'
109
+ required_rubygems_version: !ruby/object:Gem::Requirement
110
+ requirements:
111
+ - - ">="
112
+ - !ruby/object:Gem::Version
113
+ version: '0'
114
+ requirements: []
115
+ rubyforge_project:
116
+ rubygems_version: 2.6.8
117
+ signing_key:
118
+ specification_version: 4
119
+ summary: Adds BBCode support to Thredded.
120
+ test_files: []