sir-trevor-rails 0.3.0 → 0.4.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.
- checksums.yaml +4 -4
- data/Gemfile.lock +58 -62
- data/README.md +12 -73
- data/app/views/sir-trevor/blocks/_list_block.html.erb +3 -0
- data/app/views/sir-trevor/blocks/_quote_block.html.erb +3 -3
- data/app/views/sir-trevor/blocks/_text_block.html.erb +2 -2
- data/app/views/sir-trevor/blocks/_tweet_block.html.erb +4 -4
- data/app/views/sir-trevor/blocks/_video_block.html.erb +5 -5
- data/config/initializers/validators.rb +4 -2
- data/lib/generators/sir_trevor/block/templates/_block.html.erb +2 -2
- data/lib/sir-trevor-rails.rb +7 -3
- data/lib/sir-trevor/helpers/form_builder.rb +2 -2
- data/lib/sir-trevor/helpers/form_helper.rb +12 -6
- data/lib/sir-trevor/helpers/view_helper.rb +41 -40
- data/lib/sir-trevor/version.rb +1 -1
- data/sir-trevor-rails.gemspec +6 -2
- metadata +35 -34
- data/Rakefile +0 -10
- data/app/assets/images/sir-trevor/icons/block_editor_blockquote.png +0 -0
- data/app/assets/images/sir-trevor/icons/block_editor_embed.png +0 -0
- data/app/assets/images/sir-trevor/icons/block_editor_image.png +0 -0
- data/app/assets/images/sir-trevor/icons/block_editor_list.png +0 -0
- data/app/assets/images/sir-trevor/icons/block_editor_text.png +0 -0
- data/app/assets/images/sir-trevor/icons/block_editor_tweet.png +0 -0
- data/app/assets/images/sir-trevor/icons/block_editor_video.png +0 -0
- data/app/assets/images/sir-trevor/icons/close.gif +0 -0
- data/app/assets/images/sir-trevor/icons/handle.gif +0 -0
- data/app/assets/images/sir-trevor/icons/new_image.png +0 -0
- data/app/assets/images/sir-trevor/icons/new_tweet.png +0 -0
- data/app/assets/images/sir-trevor/icons/new_video.png +0 -0
- data/app/assets/images/sir-trevor/icons/quote.png +0 -0
- data/app/assets/images/sir-trevor/placeholders/placeholder.jpg +0 -0
- data/app/assets/images/sir-trevor/placeholders/post_placeholder.jpg +0 -0
- data/app/assets/images/sir-trevor/placeholders/thumbnail_placeholder.jpg +0 -0
- data/app/assets/javascript/sir-trevor.js +0 -2
- data/app/assets/javascript/sir-trevor/libs/underscore.js +0 -32
- data/app/assets/javascript/sir-trevor/sir-trevor.js +0 -2349
- data/app/assets/stylesheets/sir-trevor.css +0 -4
- data/app/assets/stylesheets/sir-trevor/icons.css.erb +0 -47
- data/app/assets/stylesheets/sir-trevor/sir-trevor.css +0 -439
- data/app/views/sir-trevor/blocks/_gallery_block.html.erb +0 -6
- data/app/views/sir-trevor/blocks/_ul_block.html.erb +0 -3
- data/lib/generators/sir_trevor/block/block_generator.rb +0 -37
- data/lib/generators/sir_trevor/block/templates/_block.css.erb +0 -7
- data/lib/generators/sir_trevor/block/templates/_block.js +0 -122
- data/lib/generators/sir_trevor/block/templates/_block.png +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3d0668026fc08c29b2dcd100108e308f951d3cf2
|
4
|
+
data.tar.gz: fd580f1cb8dd62d6b2c5e51892ec2e7a22c51713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fc6c224901a0f95b6cd9aa56fd5cc401f8b88c4d3ae4237f7aba6faed8efbde517c125b0be48bfd1cc1bf82d8710da03b82eaa6dfc4857a11bbc8cd6b337fde5
|
7
|
+
data.tar.gz: 01081da708b0e90c55b29bffd08715fb07af2e4cf9652117e3c26287fe22b7057f188a45be7ab81bc208b347646d2ca44469425d622220806274d0bc90119556
|
data/Gemfile.lock
CHANGED
@@ -1,9 +1,11 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
sir-trevor-rails (0.
|
4
|
+
sir-trevor-rails (0.4.0)
|
5
|
+
activemodel
|
5
6
|
activesupport (>= 3.0.7)
|
6
7
|
jquery-rails
|
8
|
+
multi_json
|
7
9
|
rails (>= 3.0.7)
|
8
10
|
redcarpet (~> 2.0.1)
|
9
11
|
twitter-text (~> 1.4)
|
@@ -11,84 +13,78 @@ PATH
|
|
11
13
|
GEM
|
12
14
|
remote: http://rubygems.org/
|
13
15
|
specs:
|
14
|
-
actionmailer (
|
15
|
-
actionpack (=
|
16
|
+
actionmailer (4.0.0)
|
17
|
+
actionpack (= 4.0.0)
|
16
18
|
mail (~> 2.5.3)
|
17
|
-
actionpack (
|
18
|
-
|
19
|
-
|
20
|
-
builder (~> 3.0.0)
|
19
|
+
actionpack (4.0.0)
|
20
|
+
activesupport (= 4.0.0)
|
21
|
+
builder (~> 3.1.0)
|
21
22
|
erubis (~> 2.7.0)
|
22
|
-
|
23
|
-
rack (~>
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
builder (3.0.4)
|
23
|
+
rack (~> 1.5.2)
|
24
|
+
rack-test (~> 0.6.2)
|
25
|
+
activemodel (4.0.0)
|
26
|
+
activesupport (= 4.0.0)
|
27
|
+
builder (~> 3.1.0)
|
28
|
+
activerecord (4.0.0)
|
29
|
+
activemodel (= 4.0.0)
|
30
|
+
activerecord-deprecated_finders (~> 1.0.2)
|
31
|
+
activesupport (= 4.0.0)
|
32
|
+
arel (~> 4.0.0)
|
33
|
+
activerecord-deprecated_finders (1.0.3)
|
34
|
+
activesupport (4.0.0)
|
35
|
+
i18n (~> 0.6, >= 0.6.4)
|
36
|
+
minitest (~> 4.2)
|
37
|
+
multi_json (~> 1.3)
|
38
|
+
thread_safe (~> 0.1)
|
39
|
+
tzinfo (~> 0.3.37)
|
40
|
+
arel (4.0.0)
|
41
|
+
atomic (1.1.13)
|
42
|
+
builder (3.1.4)
|
43
43
|
erubis (2.7.0)
|
44
|
-
hike (1.2.
|
45
|
-
i18n (0.6.
|
46
|
-
|
47
|
-
jquery-rails (2.2.1)
|
44
|
+
hike (1.2.3)
|
45
|
+
i18n (0.6.5)
|
46
|
+
jquery-rails (3.0.4)
|
48
47
|
railties (>= 3.0, < 5.0)
|
49
48
|
thor (>= 0.14, < 2.0)
|
50
|
-
|
51
|
-
mail (2.5.3)
|
52
|
-
i18n (>= 0.4.0)
|
49
|
+
mail (2.5.4)
|
53
50
|
mime-types (~> 1.16)
|
54
51
|
treetop (~> 1.4.8)
|
55
|
-
mime-types (1.
|
56
|
-
|
52
|
+
mime-types (1.25)
|
53
|
+
minitest (4.7.5)
|
54
|
+
multi_json (1.7.9)
|
57
55
|
polyglot (0.3.3)
|
58
|
-
rack (1.
|
59
|
-
rack-cache (1.2)
|
60
|
-
rack (>= 0.4)
|
61
|
-
rack-ssl (1.3.3)
|
62
|
-
rack
|
56
|
+
rack (1.5.2)
|
63
57
|
rack-test (0.6.2)
|
64
58
|
rack (>= 1.0)
|
65
|
-
rails (
|
66
|
-
actionmailer (=
|
67
|
-
actionpack (=
|
68
|
-
activerecord (=
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
railties (
|
74
|
-
actionpack (=
|
75
|
-
activesupport (=
|
76
|
-
rack-ssl (~> 1.3.2)
|
59
|
+
rails (4.0.0)
|
60
|
+
actionmailer (= 4.0.0)
|
61
|
+
actionpack (= 4.0.0)
|
62
|
+
activerecord (= 4.0.0)
|
63
|
+
activesupport (= 4.0.0)
|
64
|
+
bundler (>= 1.3.0, < 2.0)
|
65
|
+
railties (= 4.0.0)
|
66
|
+
sprockets-rails (~> 2.0.0)
|
67
|
+
railties (4.0.0)
|
68
|
+
actionpack (= 4.0.0)
|
69
|
+
activesupport (= 4.0.0)
|
77
70
|
rake (>= 0.8.7)
|
78
|
-
|
79
|
-
|
80
|
-
rake (10.0.4)
|
81
|
-
rdoc (3.12.2)
|
82
|
-
json (~> 1.4)
|
71
|
+
thor (>= 0.18.1, < 2.0)
|
72
|
+
rake (10.1.0)
|
83
73
|
redcarpet (2.0.1)
|
84
|
-
sprockets (2.
|
74
|
+
sprockets (2.10.0)
|
85
75
|
hike (~> 1.2)
|
86
76
|
multi_json (~> 1.0)
|
87
77
|
rack (~> 1.0)
|
88
78
|
tilt (~> 1.1, != 1.3.0)
|
79
|
+
sprockets-rails (2.0.0)
|
80
|
+
actionpack (>= 3.0)
|
81
|
+
activesupport (>= 3.0)
|
82
|
+
sprockets (~> 2.8)
|
89
83
|
thor (0.18.1)
|
90
|
-
|
91
|
-
|
84
|
+
thread_safe (0.1.2)
|
85
|
+
atomic
|
86
|
+
tilt (1.4.1)
|
87
|
+
treetop (1.4.15)
|
92
88
|
polyglot
|
93
89
|
polyglot (>= 0.3.1)
|
94
90
|
twitter-text (1.6.1)
|
data/README.md
CHANGED
@@ -1,73 +1,18 @@
|
|
1
1
|
# Sir Trevor Rails
|
2
2
|
|
3
|
-
A Rails
|
3
|
+
A set of Rails Helpers for Sir Trevor JS.
|
4
4
|
|
5
5
|
# Usage
|
6
6
|
|
7
|
-
|
7
|
+
REWRITE REQUIRED.
|
8
8
|
|
9
|
-
|
10
|
-
gem 'sir-trevor-rails'
|
11
|
-
```
|
12
|
-
|
13
|
-
```bash
|
14
|
-
bundle install
|
15
|
-
```
|
16
|
-
|
17
|
-
Require SirTrevor in your `application_controller.rb`
|
18
|
-
|
19
|
-
```ruby
|
20
|
-
require 'sir-trevor-rails'
|
21
|
-
```
|
22
|
-
|
23
|
-
Include Sir Trevor in your `application.css` file
|
24
|
-
|
25
|
-
```css
|
26
|
-
*= require sir-trevor
|
27
|
-
```
|
28
|
-
|
29
|
-
Include Sir Trevor in your `application.js` file
|
30
|
-
|
31
|
-
```js
|
32
|
-
//= require sir-trevor
|
33
|
-
```
|
34
|
-
|
35
|
-
In your view file for your editable content (must be a 'text' field as we store the JSON here) here we have a field called 'content'
|
36
|
-
|
37
|
-
```ruby
|
38
|
-
f.sir_trevor_text_area :content
|
39
|
-
```
|
40
|
-
|
41
|
-
And instantiate a new `SirTrevor.Editor` instance in your Javascript.
|
42
|
-
|
43
|
-
```javascript
|
44
|
-
$(function(){
|
45
|
-
var editor = new SirTrevor.Editor({ el: $('.sir-trevor-area') });
|
46
|
-
});
|
47
|
-
```
|
48
|
-
|
49
|
-
Or for multiple instances:
|
50
|
-
|
51
|
-
```javascript
|
52
|
-
$(function(){
|
53
|
-
var instances = $('.sir-trevor-area'),
|
54
|
-
l = instances.length, instance;
|
55
|
-
|
56
|
-
while (l--) {
|
57
|
-
instance = $(instances[l]);
|
58
|
-
new SirTrevor.Editor({ el: instance });
|
59
|
-
}
|
60
|
-
|
61
|
-
});
|
62
|
-
```
|
63
|
-
|
64
|
-
To render your content (in your view file)
|
65
|
-
|
66
|
-
```ruby
|
67
|
-
<%= render_sir_trevor(post.content) %>
|
68
|
-
```
|
9
|
+
# Requirements
|
69
10
|
|
70
|
-
|
11
|
+
- Rails 3.x
|
12
|
+
- jQuery
|
13
|
+
- (Eventable)[https://github.com/madebymany/eventable]
|
14
|
+
- (Underscore)[https://github.com/jashkenas/underscore]
|
15
|
+
- (Sir Trevor JS)[https://github.com/madebymany/sir-trevor-js]
|
71
16
|
|
72
17
|
# Generators
|
73
18
|
|
@@ -83,13 +28,13 @@ This will copy all of the SirTrevor block partials into `app/views/sir-trevor/bl
|
|
83
28
|
|
84
29
|
# Handling image uploads
|
85
30
|
|
86
|
-
We don't provide a default image uploader out of the box, because everyone will have different requirements. Until we provide a full example project, have a look at [this gist](https://gist.github.com/
|
31
|
+
We don't provide a default image uploader out of the box, because everyone will have different requirements. Until we provide a full example project, have a look at [this gist](https://gist.github.com/cjbell/7091537) which allows uploads using CarrierWave and Fog (for S3).
|
87
32
|
|
88
33
|
# Helper methods
|
89
34
|
|
90
35
|
**`render_sir_trevor`**
|
91
36
|
|
92
|
-
Parses the blocks JSON content, loops through each piece of block content and render the appropriate partial for the block.
|
37
|
+
Parses the blocks JSON content, loops through each piece of block content and render the appropriate partial for the block.
|
93
38
|
|
94
39
|
**`render_sir_trevor_image`**
|
95
40
|
|
@@ -99,19 +44,13 @@ Returns the first available SirTrevor image from the supplied JSON.
|
|
99
44
|
|
100
45
|
Returns an image tag from a SirTrevor Image block
|
101
46
|
|
102
|
-
**`pluck_sir_trevor_type
|
47
|
+
**`pluck_sir_trevor_type`**
|
103
48
|
|
104
49
|
Get the first instance of a specified SirTrevor block type from the supplied JSON
|
105
50
|
|
106
|
-
# Requirements
|
107
|
-
|
108
|
-
- Rails 3.x
|
109
|
-
- jQuery
|
110
|
-
- Underscore.js (bundled)
|
111
|
-
|
112
51
|
# To do
|
113
52
|
|
114
|
-
- Add tests
|
53
|
+
- Add tests
|
115
54
|
|
116
55
|
# Licence
|
117
56
|
|
@@ -1,4 +1,4 @@
|
|
1
1
|
<div class="content-block quote-block">
|
2
|
-
|
3
|
-
|
4
|
-
</div>
|
2
|
+
<%= sir_trevor_markdown block[:text] %>
|
3
|
+
<%= content_tag(:cite, sanitize("– #{block[:cite]}", tags: %w{a}), class: "quote") unless block[:cite].nil? %>
|
4
|
+
</div>
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<div class="content-block text-block">
|
2
|
-
|
3
|
-
</div>
|
2
|
+
<%= sir_trevor_markdown block[:text] %>
|
3
|
+
</div>
|
@@ -1,6 +1,6 @@
|
|
1
1
|
<div class="content-block tweet-block">
|
2
|
-
<%= link_to image_tag("//twitter.com/api/users/profile_image/#{ block[
|
3
|
-
<p><%= auto_link(block[
|
4
|
-
<cite>From <%= link_to "@#{ block[
|
5
|
-
<time datetime="<%= block[
|
2
|
+
<%= link_to image_tag("//twitter.com/api/users/profile_image/#{ block[:user][:screen_name] }?size=bigger", :class => 'img'), "http://twitter.com/#{ block[:user][:screen_name] }" %>
|
3
|
+
<p><%= sanitize Twitter::Autolink.auto_link(block[:text], url_entities: (block[:entities].values_at(:urls, :media).flatten.compact.uniq rescue nil)), tags: %w{a}, attributes: %w{href rel target} %></p>
|
4
|
+
<cite>From <%= link_to "@#{ block[:user][:screen_name] }", "http://twitter.com/#{ block[:user][:screen_name] }" %> on Twitter:</cite>
|
5
|
+
<time datetime="<%= block[:created_at] %>">(<%= link_to Time.parse(block[:created_at]), "http://twitter.com/#{block[:user][:screen_name]}/status/#{block[:id_str]}" %>)</time>
|
6
6
|
</div>
|
@@ -1,7 +1,7 @@
|
|
1
1
|
<div class="content-block video-block">
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
2
|
+
<% if block[:source] == 'vimeo' %>
|
3
|
+
<iframe src="//player.vimeo.com/video/<%= block[:remote_id] %>?title=1&byline=1&portrait=1&autoplay=0" width="600" height="400" frameborder="0" webkitAllowFullScreen mozallowfullscreen allowFullScreen></iframe>
|
4
|
+
<% elsif block[:source] == 'youtube' %>
|
5
|
+
<iframe width="600" height="400" src="//www.youtube.com/embed/<%= block[:remote_id] %>" frameborder="0" allowfullscreen></iframe>
|
6
|
+
<% end %>
|
7
7
|
</div>
|
@@ -1,10 +1,12 @@
|
|
1
|
+
require 'active_model/validator'
|
2
|
+
|
1
3
|
class IsJsonValidator < ActiveModel::EachValidator
|
2
4
|
def validate_each(record, attribute, value)
|
3
|
-
@json =
|
5
|
+
@json = SirTrevor.parse_json(value)
|
4
6
|
record.errors.add(attribute, "is empty") if @json.empty?
|
5
7
|
rescue TypeError => e
|
6
8
|
record.errors.add(attribute, "is not valid JSON: #{e.message}")
|
7
9
|
rescue JSON::JSONError => e
|
8
10
|
record.errors.add(attribute, "is not valid JSON: #{e.message}")
|
9
11
|
end
|
10
|
-
end
|
12
|
+
end
|
@@ -1,3 +1,3 @@
|
|
1
1
|
<div class="content-block -block">
|
2
|
-
|
3
|
-
</div>
|
2
|
+
<%= block.inspect %>
|
3
|
+
</div>
|
data/lib/sir-trevor-rails.rb
CHANGED
@@ -2,7 +2,7 @@ require "active_support/dependencies"
|
|
2
2
|
|
3
3
|
module SirTrevor
|
4
4
|
|
5
|
-
|
5
|
+
mattr_accessor :app_root
|
6
6
|
|
7
7
|
module Helpers
|
8
8
|
autoload :ViewHelper, 'sir-trevor/helpers/view_helper'
|
@@ -11,9 +11,13 @@ module SirTrevor
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.setup
|
14
|
-
|
14
|
+
yield self
|
15
|
+
end
|
16
|
+
|
17
|
+
def self.parse_json(json)
|
18
|
+
MultiJson.load(json, symbolize_keys: true)
|
15
19
|
end
|
16
20
|
|
17
21
|
end
|
18
22
|
|
19
|
-
require "sir-trevor/engine"
|
23
|
+
require "sir-trevor/engine"
|
@@ -4,8 +4,8 @@ module SirTrevor
|
|
4
4
|
extend ActiveSupport::Concern
|
5
5
|
|
6
6
|
def sir_trevor_text_area(method, options = {})
|
7
|
-
@template.send(
|
7
|
+
@template.send(:sir_trevor_text_area, @object_name, method, objectify_options(options))
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
@@ -11,14 +11,20 @@ module SirTrevor
|
|
11
11
|
|
12
12
|
options = { :language => I18n.locale.to_s }.merge(options)
|
13
13
|
input_html = (options.delete(:input_html) || {})
|
14
|
-
input_html[
|
14
|
+
input_html[:class] = "sir-trevor-area visuallyhidden"
|
15
15
|
hash = input_html.stringify_keys
|
16
16
|
|
17
|
-
instance_tag = ActionView::Base::InstanceTag.new(object_name, method, self, options.delete(:object))
|
18
|
-
instance_tag.send(:add_default_name_and_id, hash)
|
19
|
-
|
20
17
|
output_buffer = ActiveSupport::SafeBuffer.new
|
21
|
-
|
18
|
+
# support both Rails 3 & 4
|
19
|
+
if defined? ActionView::Base::InstanceTag
|
20
|
+
instance_tag = ActionView::Base::InstanceTag.new(object_name, method, self, options.delete(:object))
|
21
|
+
instance_tag.send(:add_default_name_and_id, hash)
|
22
|
+
output_buffer << instance_tag.to_text_area_tag(input_html)
|
23
|
+
else
|
24
|
+
instance_tag = ActionView::Helpers::Tags::TextArea.new(object_name, method, self, input_html)
|
25
|
+
instance_tag.send(:add_default_name_and_id, hash)
|
26
|
+
output_buffer << instance_tag.render
|
27
|
+
end
|
22
28
|
|
23
29
|
output_buffer
|
24
30
|
|
@@ -26,4 +32,4 @@ module SirTrevor
|
|
26
32
|
|
27
33
|
end
|
28
34
|
end
|
29
|
-
end
|
35
|
+
end
|
@@ -3,77 +3,78 @@ module SirTrevor
|
|
3
3
|
module ViewHelper
|
4
4
|
|
5
5
|
extend ActiveSupport::Concern
|
6
|
-
|
7
|
-
|
8
|
-
def render_sir_trevor(json, image_type = 'large')
|
6
|
+
|
7
|
+
def render_sir_trevor(json, image_type = :large)
|
9
8
|
if hash = parse_sir_trevor(json)
|
10
|
-
hash.map { |object|
|
9
|
+
safe_join hash.map { |object|
|
11
10
|
render_sir_trevor_block(object, image_type)
|
12
|
-
}.compact
|
11
|
+
}.compact
|
13
12
|
else
|
14
13
|
''
|
15
14
|
end
|
16
15
|
end
|
17
16
|
|
18
|
-
def render_sir_trevor_block(object, image_type =
|
19
|
-
view_name = "sir-trevor/blocks/#{object[
|
17
|
+
def render_sir_trevor_block(object, image_type = :large)
|
18
|
+
view_name = "sir-trevor/blocks/#{object[:type].to_s.downcase}_block"
|
20
19
|
|
21
20
|
render(view_name,
|
22
|
-
:block => object[
|
23
|
-
:image_type => image_type) if object.has_key?(
|
21
|
+
:block => object[:data],
|
22
|
+
:image_type => image_type) if object.has_key?(:data)
|
24
23
|
end
|
25
24
|
|
26
|
-
def render_sir_trevor_image(json, image_type =
|
27
|
-
image = pluck_sir_trevor_type(json,
|
28
|
-
|
29
|
-
unless image.nil?
|
30
|
-
render(:partial => "sir-trevor/blocks/image_block",
|
25
|
+
def render_sir_trevor_image(json, image_type = :large)
|
26
|
+
image = pluck_sir_trevor_type(json, :image)
|
27
|
+
|
28
|
+
unless image.nil?
|
29
|
+
render(:partial => "sir-trevor/blocks/image_block",
|
30
|
+
:locals => { :block => image[:data], :image_type => image_type,
|
31
|
+
:protocol => request.protocol }) if image.has_key?(:data)
|
31
32
|
end
|
32
33
|
end
|
33
|
-
|
34
|
-
def sir_trevor_image_tag(block, image_type)
|
34
|
+
|
35
|
+
def sir_trevor_image_tag(block, image_type)
|
35
36
|
# Does the image type exist on the block?
|
36
|
-
if(block[
|
37
|
-
|
38
|
-
image = block[
|
39
|
-
|
40
|
-
image_url = image[
|
41
|
-
width = image[
|
42
|
-
height = image[
|
43
|
-
|
37
|
+
if(block[:file].present? && block[:file][image_type].present?)
|
38
|
+
|
39
|
+
image = block[:file][image_type]
|
40
|
+
|
41
|
+
image_url = image[:url]
|
42
|
+
width = image[:width] if image[:width].present?
|
43
|
+
height = image[:height] if image[:height].present?
|
44
|
+
|
44
45
|
options = {
|
45
46
|
:class => "sir-trevor-image #{image_type}",
|
46
|
-
:alt => block[
|
47
|
+
:alt => block[:description]
|
47
48
|
}
|
48
|
-
|
49
|
+
|
49
50
|
options.merge!({ :width => width }) unless width.nil?
|
50
51
|
options.merge!({ :height => height }) unless height.nil?
|
51
|
-
|
52
|
+
|
52
53
|
image_tag(image_url, options) unless image_url.nil?
|
53
54
|
end
|
54
55
|
end
|
55
56
|
|
56
57
|
def sir_trevor_markdown(text)
|
57
|
-
|
58
|
-
|
59
|
-
|
58
|
+
renderer = CustomMarkdownFormatter.new(:hard_wrap => true, :filter_html => true,
|
59
|
+
:autolink => true, :no_intraemphasis => true,
|
60
|
+
:fenced_code => true)
|
61
|
+
markdown = Redcarpet::Markdown.new(renderer)
|
60
62
|
markdown.render(text).html_safe
|
61
63
|
end
|
62
64
|
|
63
65
|
def parse_sir_trevor(json)
|
64
|
-
hash =
|
65
|
-
|
66
|
-
|
67
|
-
hash["data"]
|
66
|
+
hash = (json.is_a?(String) ? SirTrevor.parse_json(json) : json)
|
67
|
+
return false unless hash.has_key?(:data)
|
68
|
+
hash[:data]
|
68
69
|
end
|
69
70
|
|
70
71
|
private
|
71
72
|
# Get's the first instance of a type from the specified JSON
|
72
|
-
def pluck_sir_trevor_type(json, type)
|
73
|
-
hash =
|
74
|
-
if hash.has_key?(
|
75
|
-
item = hash[
|
76
|
-
item.first
|
73
|
+
def pluck_sir_trevor_type(json, type)
|
74
|
+
hash = SirTrevor.parse_json(json)
|
75
|
+
if hash.has_key?(:data)
|
76
|
+
item = hash[:data].select { |item| item[:type] == type }
|
77
|
+
item.first[:text] if item.any?
|
77
78
|
end
|
78
79
|
end
|
79
80
|
end
|
@@ -84,7 +85,7 @@ class CustomMarkdownFormatter < Redcarpet::Render::HTML
|
|
84
85
|
def block_code(code, language)
|
85
86
|
"<p>" << code << "</p>"
|
86
87
|
end
|
87
|
-
|
88
|
+
|
88
89
|
def codespan(code)
|
89
90
|
code
|
90
91
|
end
|