-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Upgrade storyblok-richtext-renderer and add custom marks/nodes (#512)
- Loading branch information
Showing
10 changed files
with
168 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Storyblok::Richtext | ||
module Marks | ||
class Color < Mark | ||
|
||
def matching | ||
@node['type'] === 'color' | ||
end | ||
|
||
def tag | ||
attrs = { | ||
style: "color:#{@node['attrs']['color']};" | ||
} | ||
[{ | ||
tag: 'span', | ||
attrs: attrs | ||
}] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
module Storyblok::Richtext | ||
module Marks | ||
class Em < Mark | ||
def matching | ||
@node['type'] === 'em' | ||
end | ||
|
||
def tag | ||
'em' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Storyblok::Richtext | ||
module Marks | ||
class FontFamily < Mark | ||
|
||
def matching | ||
@node['type'] === 'fontFamily' | ||
end | ||
|
||
def tag | ||
attrs = { | ||
style: "font-family:#{@node['attrs']['fontFamily']};" | ||
} | ||
[{ | ||
tag: 'span', | ||
attrs: attrs | ||
}] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
module Storyblok::Richtext | ||
module Marks | ||
class FontSize < Mark | ||
|
||
def matching | ||
@node['type'] === 'fontSize' | ||
end | ||
|
||
def tag | ||
attrs = { | ||
style: "font-size:#{@node['attrs']['fontSize']};" | ||
} | ||
[{ | ||
tag: 'span', | ||
attrs: attrs | ||
}] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module Storyblok::Richtext | ||
module Marks | ||
class Strikethrough < Mark | ||
|
||
def matching | ||
@node['type'] === 'strikethrough' | ||
end | ||
|
||
def tag | ||
's' | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
module Storyblok::Richtext | ||
module Marks | ||
class TextStyle < Mark | ||
|
||
def matching | ||
@node['type'] === 'textStyle' | ||
end | ||
|
||
def tag | ||
color = "color:#{@node['attrs']['color']};" | ||
font_size = "font-size:#{@node['attrs']['fontSize']};" | ||
font_family = "font-family:#{@node['attrs']['fontFamily']};" | ||
text_decoration = "text-decoration:#{@node['attrs']['textDecoration']};" | ||
attrs = { | ||
style: "#{color} #{font_size} #{font_family} #{text_decoration}" | ||
} | ||
[{ | ||
tag: 'span', | ||
attrs: attrs | ||
}] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
module Storyblok::Richtext | ||
module Nodes | ||
class Image < Node | ||
|
||
def matching | ||
@node['type'] === 'image' | ||
end | ||
|
||
def single_tag | ||
attrs = {} | ||
if !@node['attrs'].nil? | ||
attrs = @node['attrs'].slice('src', 'alt', 'title') | ||
attrs['style'] = "width: #{@node['attrs']['width']};" | ||
end | ||
return [{ | ||
tag: "img", | ||
attrs: attrs | ||
}] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
module Storyblok::Richtext | ||
module Nodes | ||
class Paragraph < Node | ||
|
||
def matching | ||
@node['type'] === 'paragraph' | ||
end | ||
|
||
def tag | ||
if @node['attrs'] | ||
text_indent = @node['attrs']['indented'] ? '3rem' : '0' | ||
text_indent = "text-indent: #{text_indent};" | ||
margin_left = "margin-left: #{(@node['attrs']['indentLevel'] || 0) * 48}px;" | ||
line_height = "line-height: #{@node['attrs']['lineHeight']};" | ||
attrs = { | ||
style: "#{text_indent} #{margin_left} #{line_height}" | ||
} | ||
[{ | ||
tag: 'p', | ||
attrs: attrs, | ||
}] | ||
else | ||
'p' | ||
end | ||
end | ||
end | ||
end | ||
end |