Module: Ronin::Exploits::Mixins::HTML
- Included in:
- XSS
- Defined in:
- lib/ronin/exploits/mixins/html.rb
Overview
Mixin which adds methods for building HTML.
Instance Method Summary collapse
-
#attr(name, value, name_case: nil, quote: :double) ⇒ String
Formats an HTML attribute.
-
#attr_list(attrs, **kwargs) ⇒ String
Formats an HTML attributes list.
-
#attr_name(name, name_case: nil) ⇒ String
Formats an HTML attribute name.
-
#tag(name, tag_case: nil, attr_case: nil, attr_quote: :double, text: nil, **attrs) { ... } ⇒ String
Formats an HTML tag.
-
#tag_name(name, name_case: nil) ⇒ String
Formats an HTML tag name.
Instance Method Details
#attr(name, value, name_case: nil, quote: :double) ⇒ String
Formats an HTML attribute.
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/ronin/exploits/mixins/html.rb', line 81 def attr(name,value, name_case: nil, quote: :double) name = attr_name(name, name_case: name_case) value = Support::Encoding::HTML.escape(value.to_s) quoted_value = case quote when :double "\"#{value}\"" when :single "'#{value}'" when :backtick "`#{value}`" when nil value.gsub(' ',' ') else raise(ArgumentError,"quote keyword argument (#{quote.inspect}) was not :double, :single, :backtick, or nil") end return "#{name}=#{quoted_value}" end |
#attr_list(attrs, **kwargs) ⇒ String
Formats an HTML attributes list.
122 123 124 125 126 |
# File 'lib/ronin/exploits/mixins/html.rb', line 122 def attr_list(attrs,**kwargs) attrs.map { |name,value| attr(name,value,**kwargs) }.join(' ') end |
#attr_name(name, name_case: nil) ⇒ String
Formats an HTML attribute name.
47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/ronin/exploits/mixins/html.rb', line 47 def attr_name(name, name_case: nil) name = name.to_s case name_case when :random then name.random_case when :lower then name.downcase when :upper then name.upcase when nil then name else raise(ArgumentError,"HTML attr name case (#{name_case.inspect}) was not :lower, :upper, :random, or nil") end end |
#tag(name, tag_case: nil, attr_case: nil, attr_quote: :double, text: nil, **attrs) { ... } ⇒ String
Formats an HTML tag.
195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 |
# File 'lib/ronin/exploits/mixins/html.rb', line 195 def tag(name, tag_case: nil, attr_case: nil, attr_quote: :double, text: nil, **attrs) tag_name = self.tag_name(name, name_case: tag_case) tag_contents = if !attrs.empty? attrs = attr_list(attrs, name_case: attr_case, quote: attr_quote) "#{tag_name} #{attrs}" else tag_name end if block_given? "<#{tag_contents}>#{yield}</#{tag_name}>" elsif text "<#{tag_contents}>#{text}</#{tag_name}>" else "<#{tag_contents}/>" end end |
#tag_name(name, name_case: nil) ⇒ String
Formats an HTML tag name.
143 144 145 146 147 148 149 150 151 152 153 154 |
# File 'lib/ronin/exploits/mixins/html.rb', line 143 def tag_name(name, name_case: nil) name = name.to_s case name_case when :random then name.random_case when :lower then name.downcase when :upper then name.upcase when nil then name else raise(ArgumentError,"HTML tag name case (#{name_case.inspect}) was not :lower, :upper, :random, or nil") end end |