contentful_rails 0.0.6.1 → 0.0.7
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca234cec854ccb57f25cad68cce520664212992a
|
4
|
+
data.tar.gz: af4bf4031e663ce175917da5ad2fadddb98fe662
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9041135f6cf91254144e1a2fb78b42afd724cd56daa0f0e2d161490b18b7278ebfec38c0b24fdc7cce57c7c5e7b674db1c14aa66be7fe47b7b2e5a9308ca6867
|
7
|
+
data.tar.gz: c8f8098b982a102e1eaafe35af32020d2fe02a6ad097097efea2b19b5cb196bafac5b593ac86907d006fe1073a3b7e8400a3ca4b674087acf33706170aca37e2
|
@@ -1,10 +1,45 @@
|
|
1
1
|
module ContentfulRails
|
2
2
|
module MarkdownHelper
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
3
|
+
# Return HTML which is passed through the Redcloth markdown processor, using a custom renderer
|
4
|
+
# so that we can manipulate images using contentful's URL-based API.
|
5
|
+
# NOTE that this is super-permissive out of the box. Set options to suit when you call the method.
|
6
|
+
# @param renderer_options [Hash] of options from https://github.com/vmg/redcarpet#darling-i-packed-you-a-couple-renderers-for-lunch
|
7
|
+
# @param markdown_options [Hash] of options from https://github.com/vmg/redcarpet#and-its-like-really-simple-to-use
|
8
|
+
def parse_markdown(markdown_string, renderer_options: {}, markdown_options: {}, image_options: {})
|
9
|
+
markdown_opts = {
|
10
|
+
no_intr_emphasis: true,
|
11
|
+
tables: true,
|
12
|
+
fenced_code_blocks: true,
|
13
|
+
autolink: true,
|
14
|
+
disable_indented_code_blocks: true,
|
15
|
+
strikethrough: true,
|
16
|
+
lax_spacing: true,
|
17
|
+
space_after_headers: false,
|
18
|
+
superscript: true,
|
19
|
+
underline: true,
|
20
|
+
highlight: true,
|
21
|
+
footnotes: true
|
22
|
+
}.merge(markdown_options)
|
23
|
+
|
24
|
+
renderer_opts = {
|
25
|
+
filter_html: false, # we want to allow HTML in the markdown blocks
|
26
|
+
no_images: false,
|
27
|
+
no_links: false,
|
28
|
+
no_styles: false,
|
29
|
+
escape_html: false,
|
30
|
+
safe_links_only: false,
|
31
|
+
with_toc_data: true,
|
32
|
+
hard_wrap: true,
|
33
|
+
xhtml: false,
|
34
|
+
prettify: false,
|
35
|
+
link_attributes: {},
|
36
|
+
image_options: image_options
|
37
|
+
}.merge(renderer_options)
|
38
|
+
|
39
|
+
renderer = ContentfulRails::MarkdownRenderer.new(renderer_opts)
|
40
|
+
markdown = Redcarpet::Markdown.new(renderer, markdown_opts)
|
41
|
+
|
42
|
+
markdown.render(markdown_string).html_safe
|
8
43
|
end
|
9
44
|
end
|
10
45
|
end
|
data/lib/contentful_rails.rb
CHANGED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'redcarpet'
|
2
|
+
# A custom renderer for Redcarpet, which adds options for manipulating images through the URL of the image,
|
3
|
+
# and building links based on the content of the link.
|
4
|
+
#
|
5
|
+
# You can subclass this in your application, to add or manipulate specific markup to elements in the markdown.
|
6
|
+
class ContentfulRails::MarkdownRenderer < Redcarpet::Render::HTML
|
7
|
+
include ActionView::Helpers::TagHelper
|
8
|
+
def initialize(opts)
|
9
|
+
@options = opts
|
10
|
+
@image_parameters = {
|
11
|
+
w: @options[:image_options][:width], #width in px
|
12
|
+
h: @options[:image_options][:height], #height in px
|
13
|
+
fit: @options[:image_options][:fit], #crop, scale, pad, thumb
|
14
|
+
f: @options[:image_options][:focus], #top, right, bottom, left, top_right, top_left, bottom_right, bottom_left, face
|
15
|
+
fm: @options[:image_options][:format], #jpg, png
|
16
|
+
bg: @options[:image_options][:background_colour], #no idea what the options are, but 'transparent' works for pngs
|
17
|
+
r: @options[:image_options][:corner_radius], #corner radius in px
|
18
|
+
q: @options[:image_options][:quality]
|
19
|
+
}.delete_if {|k,v| v.nil?}
|
20
|
+
super
|
21
|
+
end
|
22
|
+
|
23
|
+
def image(link, title, alt_text)
|
24
|
+
# add the querystring to the image
|
25
|
+
link += "?#{@image_parameters.to_query}"
|
26
|
+
# return a content tag
|
27
|
+
content_tag(:img, nil, src: link.to_s, alt: alt_text, title: title)
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
metadata
CHANGED
@@ -1,55 +1,55 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: contentful_rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Error Creative Studio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-03-19 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: contentful_model
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: 0.0.6
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: 0.0.6
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rails
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: 4.1.8
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: 4.1.8
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: redcarpet
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ~>
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '3.2'
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ~>
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '3.2'
|
55
55
|
description: A gem to help with hooking Contentful into your Rails application
|
@@ -68,6 +68,7 @@ files:
|
|
68
68
|
- lib/contentful_rails/cached_timestamps.rb
|
69
69
|
- lib/contentful_rails/development_constraint.rb
|
70
70
|
- lib/contentful_rails/engine.rb
|
71
|
+
- lib/contentful_rails/markdown_renderer.rb
|
71
72
|
- lib/contentful_rails/version.rb
|
72
73
|
- lib/tasks/contentful_rails_tasks.rake
|
73
74
|
- test/contentful_rails_test.rb
|
@@ -83,12 +84,12 @@ require_paths:
|
|
83
84
|
- lib
|
84
85
|
required_ruby_version: !ruby/object:Gem::Requirement
|
85
86
|
requirements:
|
86
|
-
- -
|
87
|
+
- - '>='
|
87
88
|
- !ruby/object:Gem::Version
|
88
89
|
version: '0'
|
89
90
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
90
91
|
requirements:
|
91
|
-
- -
|
92
|
+
- - '>='
|
92
93
|
- !ruby/object:Gem::Version
|
93
94
|
version: '0'
|
94
95
|
requirements: []
|