Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
jekyll-theme-lcsb-frozen-components
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Iterations
Wiki
Requirements
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
R3
outreach
themes
jekyll-theme-lcsb-frozen-components
Commits
1ca6aab3
Commit
1ca6aab3
authored
3 years ago
by
Laurent Heirendt
Browse files
Options
Downloads
Patches
Plain Diff
support for variables in title
parent
068c2c0e
No related branches found
No related tags found
1 merge request
!8
support for variables in title
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
lib/jekyll/tags/rtitle.rb
+29
-5
29 additions, 5 deletions
lib/jekyll/tags/rtitle.rb
with
29 additions
and
5 deletions
lib/jekyll/tags/rtitle.rb
+
29
−
5
View file @
1ca6aab3
...
...
@@ -7,10 +7,10 @@ module Jekyll
end
def
initialize
(
tag_name
,
block_options
,
liquid_options
)
@markup
=
block_options
super
args
=
split_params
(
block_options
)
@title
=
args
[
0
]
# Optional - setting your own ID
if
args
.
length
>
1
...
...
@@ -19,23 +19,47 @@ module Jekyll
@block_id_html
=
""
end
end
# similar solution proposed here: https://stackoverflow.com/a/45393697
def
get_value
(
context
,
expr
)
args
=
split_params
(
expr
)
# title in quotes, either double or single
if
(
expr
[
0
]
==
'"'
and
expr
[
-
1
]
==
'"'
)
or
(
expr
[
0
]
==
"'"
and
expr
[
-
1
]
==
"'"
)
return
expr
[
1
..-
2
]
# expression contains a dot and is not longer than 20 characters
elsif
expr
.
include?
"."
and
args
[
0
].
length
<
20
vars
=
expr
.
split
(
'.'
)
result
=
context
vars
.
each
do
|
variable
|
result
=
result
[
variable
]
if
result
end
return
result
# title is given as a sequence of words
else
return
args
[
0
]
end
end
def
render
(
context
)
site
=
context
.
registers
[
:site
]
converter
=
site
.
find_converter_instance
(
::
Jekyll
::
Converters
::
Markdown
)
content
=
converter
.
convert
(
super
)
title
=
get_value
(
context
,
@markup
.
strip
)
output
=
<<~
EOS
<div class="rtitle"
#{
@block_id_html
}
>
<h2>
#{
@
title
}
</h2>
<h2>
#{
title
}
</h2>
<hr>
#{
content
}
</div>
EOS
output
end
end
end
end
Liquid
::
Template
.
register_tag
(
'rtitle'
,
Jekyll
::
Tags
::
RtitleTag
)
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment