slim-htag 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/LICENSE +21 -0
- data/README.adoc +35 -0
- data/lib/slim-h_tag.rb +1 -0
- data/lib/slim-htag.rb +1 -0
- data/lib/slim/h_tag.rb +4 -0
- data/lib/slim/h_tag/filter.rb +48 -0
- data/lib/slim/h_tag/version.rb +5 -0
- data/slim-htag.gemspec +22 -0
- metadata +113 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f0b52f5d4d40bad878fbb9db6e61924415ad9dba
|
4
|
+
data.tar.gz: 63d3a49e885cca0d9c1462a044b349583d31ee59
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 96eeed968e4326649f315bba0cd7ec9c4fbe6e74cf27eab97fecabd13631f1bb355ed7efb13e60a5babaa8b919d802947e051134acf6e55a36ed3471a8dd3feb
|
7
|
+
data.tar.gz: db50b9b6b92ce42cbd93bf7e339cdf2102b9ca5d2061afbfb89f935326495d38c63a59dcf198e848d6809fc26f324e989d0943777191ae4eb936b86146eb28ba
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License
|
2
|
+
|
3
|
+
Copyright 2017 Jakub Jirutka <jakub@jirutka.cz>.
|
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.
|
data/README.adoc
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
= Slim H Tag
|
2
|
+
// custom
|
3
|
+
:gem-name: slim-htag
|
4
|
+
:gh-name: jirutka/{gem-name}
|
5
|
+
:gh-branch: master
|
6
|
+
|
7
|
+
ifdef::env-github[]
|
8
|
+
image:https://travis-ci.org/{gh-name}.svg?branch={gh-branch}[Build Status, link="https://travis-ci.org/{gh-name}"]
|
9
|
+
image:https://img.shields.io/gem/v/{gem-name}.svg?style=flat[Gem Version, link="https://rubygems.org/gems/{gem-name}"]
|
10
|
+
endif::env-github[]
|
11
|
+
|
12
|
+
|
13
|
+
This project provides a filter for http://slim-lang.com/[Slim] templating engine that allows to easily define a heading tag with parametrized level (`h1`–`h6`).
|
14
|
+
|
15
|
+
|
16
|
+
== Usage
|
17
|
+
|
18
|
+
Require file `{gem-name}`.
|
19
|
+
Use tag `h` with special attribute `level` for heading level (1-6):
|
20
|
+
|
21
|
+
[source, slim]
|
22
|
+
h level=title_level =title
|
23
|
+
|
24
|
+
If `title_level = 1` and `title = "Heading"`, then the above template would be rendered as:
|
25
|
+
|
26
|
+
[source, html]
|
27
|
+
<h1>Heading</h1>
|
28
|
+
|
29
|
+
You can redefine name of the level attribute using option `htag_level_attr` (only with Slim `~> 3.0`).
|
30
|
+
|
31
|
+
|
32
|
+
== License
|
33
|
+
|
34
|
+
This project is licensed under http://opensource.org/licenses/MIT/[MIT License].
|
35
|
+
For the full text of the license, see the link:LICENSE[LICENSE] file.
|
data/lib/slim-h_tag.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'slim/h_tag'
|
data/lib/slim-htag.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require 'slim/h_tag'
|
data/lib/slim/h_tag.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'slim'
|
2
|
+
require 'temple'
|
3
|
+
|
4
|
+
module Slim
|
5
|
+
module HTag
|
6
|
+
class Filter < ::Slim::Filter
|
7
|
+
|
8
|
+
define_options htag_level_attr: 'level'
|
9
|
+
|
10
|
+
|
11
|
+
def initialize(opts = {})
|
12
|
+
super
|
13
|
+
@level_attr = options[:htag_level_attr]
|
14
|
+
end
|
15
|
+
|
16
|
+
def on_html_tag(tag, attributes, content = nil)
|
17
|
+
return super if tag != 'h'
|
18
|
+
|
19
|
+
level_index = attributes.find_index do |attrs|
|
20
|
+
attrs[0..2] == [:html, :attr, @level_attr]
|
21
|
+
end
|
22
|
+
unless level_index
|
23
|
+
fail Temple::FilterError, "Missing attribute '#{@level_attr}' on tag 'h'"
|
24
|
+
end
|
25
|
+
|
26
|
+
level_exp = attributes.delete_at(level_index).last
|
27
|
+
if level_exp[0] == :slim && level_exp[1] == :attrvalue
|
28
|
+
level_exp = [:dynamic, level_exp.last]
|
29
|
+
end
|
30
|
+
|
31
|
+
[:multi,
|
32
|
+
[:capture, (level_var = unique_name), [:escape, true, level_exp]],
|
33
|
+
[:multi,
|
34
|
+
[:static, '<h'],
|
35
|
+
[:dynamic, level_var],
|
36
|
+
attributes,
|
37
|
+
[:static, '>']],
|
38
|
+
(compile(content) if content),
|
39
|
+
[:multi,
|
40
|
+
[:static, '</h'],
|
41
|
+
[:dynamic, level_var],
|
42
|
+
[:static, '>'],
|
43
|
+
]
|
44
|
+
].compact
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/slim-htag.gemspec
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
require File.expand_path('../lib/slim/h_tag/version', __FILE__)
|
2
|
+
|
3
|
+
Gem::Specification.new do |s|
|
4
|
+
s.name = 'slim-htag'
|
5
|
+
s.version = Slim::HTag::VERSION
|
6
|
+
s.author = 'Jakub Jirutka'
|
7
|
+
s.email = 'jakub@jirutka.cz'
|
8
|
+
s.homepage = 'https://github.com/jirutka/slim-htag'
|
9
|
+
s.license = 'MIT'
|
10
|
+
|
11
|
+
s.summary = 'Slim filter providing a heading tag with parametrized (dynamic) level (h1-h6)'
|
12
|
+
|
13
|
+
s.files = Dir['lib/**/*', '*.gemspec', 'LICENSE*', 'README*']
|
14
|
+
|
15
|
+
s.required_ruby_version = '>= 2.0'
|
16
|
+
|
17
|
+
s.add_runtime_dependency 'slim', '>= 2.1', '< 4.0'
|
18
|
+
|
19
|
+
s.add_development_dependency 'rake', '~> 12.0'
|
20
|
+
s.add_development_dependency 'rspec', '~> 3.6'
|
21
|
+
s.add_development_dependency 'simplecov', '~> 0.14'
|
22
|
+
end
|
metadata
ADDED
@@ -0,0 +1,113 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: slim-htag
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jakub Jirutka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-08-12 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: slim
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.1'
|
20
|
+
- - "<"
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: '4.0'
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: !ruby/object:Gem::Requirement
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '2.1'
|
30
|
+
- - "<"
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '4.0'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: rake
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - "~>"
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '12.0'
|
40
|
+
type: :development
|
41
|
+
prerelease: false
|
42
|
+
version_requirements: !ruby/object:Gem::Requirement
|
43
|
+
requirements:
|
44
|
+
- - "~>"
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
version: '12.0'
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: rspec
|
49
|
+
requirement: !ruby/object:Gem::Requirement
|
50
|
+
requirements:
|
51
|
+
- - "~>"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '3.6'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
requirements:
|
58
|
+
- - "~>"
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '3.6'
|
61
|
+
- !ruby/object:Gem::Dependency
|
62
|
+
name: simplecov
|
63
|
+
requirement: !ruby/object:Gem::Requirement
|
64
|
+
requirements:
|
65
|
+
- - "~>"
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0.14'
|
68
|
+
type: :development
|
69
|
+
prerelease: false
|
70
|
+
version_requirements: !ruby/object:Gem::Requirement
|
71
|
+
requirements:
|
72
|
+
- - "~>"
|
73
|
+
- !ruby/object:Gem::Version
|
74
|
+
version: '0.14'
|
75
|
+
description:
|
76
|
+
email: jakub@jirutka.cz
|
77
|
+
executables: []
|
78
|
+
extensions: []
|
79
|
+
extra_rdoc_files: []
|
80
|
+
files:
|
81
|
+
- LICENSE
|
82
|
+
- README.adoc
|
83
|
+
- lib/slim-h_tag.rb
|
84
|
+
- lib/slim-htag.rb
|
85
|
+
- lib/slim/h_tag.rb
|
86
|
+
- lib/slim/h_tag/filter.rb
|
87
|
+
- lib/slim/h_tag/version.rb
|
88
|
+
- slim-htag.gemspec
|
89
|
+
homepage: https://github.com/jirutka/slim-htag
|
90
|
+
licenses:
|
91
|
+
- MIT
|
92
|
+
metadata: {}
|
93
|
+
post_install_message:
|
94
|
+
rdoc_options: []
|
95
|
+
require_paths:
|
96
|
+
- lib
|
97
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '2.0'
|
102
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
|
+
requirements:
|
104
|
+
- - ">="
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: '0'
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 2.6.11
|
110
|
+
signing_key:
|
111
|
+
specification_version: 4
|
112
|
+
summary: Slim filter providing a heading tag with parametrized (dynamic) level (h1-h6)
|
113
|
+
test_files: []
|