Trouble understanding HTML::Element documentation in Perl - perl

I was looking into HTML:Element documentation and came across attr_get_i method which according to documentation states that:
In list context, returns a list consisting of the values of the given
attribute for $h and for all its ancestors starting from $h and
working its way up.
Now, according to the example given there:
<html lang='i-klingon'>
<head><title>Pati Pata</title></head>
<body>
<h1 lang='la'>Stuff</h1>
<p lang='es-MX' align='center'>
Foo bar baz <cite>Quux</cite>.
</p>
<p>Hooboy.</p>
</body>
</html>
If $h is the <cite> element, $h->attr_get_i("lang") in list context will return the list ('es-MX', 'i-klingon').
Now, according to my unuderstanding the returned list should be ('es-MX', 'la', 'i-klingon') that is it should also consider <h1 lang='la'>Stuff</h1> but according to the documentation it doesn't.
Now, why am I wrong here.

The 'lang' attributes here are:
+-------------+------------------+
| lang | path |
+-------------+------------------+
| i-klingon | /html |
| la | /html/body/h1 |
| es-MX | /html/body/p |
+-------------+------------------+
The <cite> node does not have <h1> as its parent (path is /html/body/p/cite), so <h1> is not its ancestor. This is why the method does not return it.

<h1 lang='la'>Stuff</h1> is not an ancestor of <cite>, it is a sibling.

Related

How do I pass Variants as props to React Components in ReasonML?

I have tried the following approach to be able to send variants as props.
type ipAddr =
| IPV4
| IPV8;
[#react.component]
let make = () => {
let appData = Data.tileData;
<div className="App">
<header className="flex outline justify-between" />
<Content selected={ipAddr.IPV4} appData />
</div>;
};
But it throws the error,
ninja: error: rebuilding 'build.ninja': subcommand failed
I have tried sending variants directly to Component as well.
<div className="App">
<header className="flex outline justify-between" />
<Content selected=IPV4 appData />
</div>;
But it ended up returning another error
Start compiling ninja: error: dependency cycle: src/App-ReactHooksTemplate.cmj -> src/Content-ReactHooksTemplate.cmj
-> src/App-ReactHooksTemplate.cmj
Finish compiling(exit: 1)
Where am I going wrong?
DISCLAIMER: I don't know ReasonML, however
If it was OCaml, you'd just write IPV4, no need to qualify it like ipAddr.IPV4.
Perhaps this is the same in Reason?
I have solved this another way. Instead of passing the variant as prop, I simply rendered different components based on variant value.
[#react.component]
let make = () => {
let appData = Data.tileData;
switch (selected) {
| IPV4 =>
<div>
<IPV4Renderer appData />
</div>
| IPV6 =>
<div>
<IPV6Renderer appData />
</div>
};
};

What is preventing some of the content from an Invoke-WebRequest showing?

I am trying to get some acsii art characters directly from a webpage. You can navigate to the page using the following URL.
http://patorjk.com/software/taag/#p=display&f=Acrobatic&t=A
If you go to that page you will see a rendering of the character A using the Acrobatic font.
o
<|>
/ \
o/ \o
<|__ __|>
/ \
o/ \o
/v v\
/> <\
Using the following code nets me most of the page.
$fontUrlTemplate = "http://patorjk.com/software/taag/#p=display&f={0}&t={1}"
$fontName = [uri]::EscapeUriString("Acrobatic")
$character = "A"
$fontUrl = $fontUrlTemplate -f $fontName, $character
$webResult = Invoke-WebRequest $fontUrl
$webResult.Content
However when I inspect the Content the actual result I am looking for is missing.
...
<div id="maincontent" >
<div id="outputFigDisplay" ></div>
</div>
...
There should be something like this in there
<pre id="taag_output_text" style="float:left;" class="fig" contenteditable="true">...</pre>
I am sure there is a server side reason for this but I would like to better understand and, if possible, mitigate it. I have tried mucking around with -ContentType and -UserAgent but it didn't change anything

Selecting a field in Protractor

<hs-details-item>
<hs-label>Location</hs-label>
<hs-value-block>
<hs>
<hs-text-box ng-class="{'disabled': isAmenityPosting }" class="required" input-control="{title:'Location', okCallback:setJobSite, value:jobSiteName,
autocomplete:{ values:getJobSiteList, reload: true }, ss:'location'}">
<i class="icon-room"></i><span hs-placeholder="Select Location" class="ng-binding"></span>
</hs-text-box>
</hs>
<hs>
<!-- ngIf: isBarcodeShow() --><hs-button ng-class="{'disabled': soCreating }" class="barcode-special-btn smaller ng-scope" ng-if="isBarcodeShow()" hs-gesture="{handler:startScan, param: onBarcodeScanCompleted}"><i class="icon-br-code"></i></hs-button><!-- end ngIf: isBarcodeShow() -->
</hs>
</hs-value-block>
</hs-details-item>
Scenario: click on “Location” field...
What would be the best way to come up with a command in Protractor to select "location" field from the above Snippet Code?
Can it be done by not using Xpath?
Multiple options here. A sort of a non-welcomed, but short and readable way, would be to use an XPath expression and check the preceding label:
var locationTextBox = element(by.xpath("//hs-label[. = 'Location']/following::hs-text-box"));
locationTextBox.click();

How To Produce HTML Table of Filehashes - with Relative Path Only?

I want to generate a HTML table that shows a filehash (sha1) of a bunch of files in a directory; I want the filenames to be relative to my current directory - not absolute.
I know how to do all the different bits separately, but I can't figure out how to chain-them up.
Here's what I've got so far:
dir|get-filehash -Algorithm sha1
Which gives me this:
Algorithm Hash Path
--------- ---- ----
SHA1 DA39A3EE5E6B4B0D3255BFEF95601890AFD80709 C:\temp\test\empty.txt
SHA1 88A5B867C3D110207786E66523CD1E4A484DA697 C:\temp\test\hello.txt
Now I only want the hash and filename , so I can do this:
dir|get-filehash -Algorithm sha1|select-object hash, path
Which gives me:
Hash Path
---- ----
DA39A3EE5E6B4B0D3255BFEF95601890AFD80709 C:\temp\test\empty.txt
88A5B867C3D110207786E66523CD1E4A484DA697 C:\temp\test\hello.txt
So I can output this to an HTML file like this:
(dir|get-filehash -Algorithm sha1|select-object hash, path)|ConvertTo-html|add-content output.htm
[ignore the fact that this only works properly if the output file doesn't exist for now].
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/><col/></colgroup>
<tr><th>Hash</th><th>Path</th></tr>
<tr><td>DA39A3EE5E6B4B0D3255BFEF95601890AFD80709</td><td>C:\temp\test\empty.txt</td></tr>
<tr><td>88A5B867C3D110207786E66523CD1E4A484DA697</td><td>C:\temp\test\hello.txt</td></tr>
</table>
So this gives me a HTML table; but the PATH values are absolute.
I know a simple way of getting a relative path using the 'Resolve-Path' cmdlet:
dir | Resolve-Path -Relative
.\empty.txt
.\hello.txt
But I can't get it to 'fit' in the rest of my script ; I guess their might be a .NET function to do this in a different way ? Or is there some fancy ninja-use of brackets that let me squeeze this call to a cmdlet insde of the 'select-object' list ?
I tried this: but it doesn't work:
# NOTE: this code does not work !
PS > dir|get-filehash|select-object hash, (path|Resolve-Path -relative)
Made some progress on this - but the solution still isn't very satisfactory - since I also need control over the headers (rather than just 'name', 'value' which the HashTable provides).
I can get these headers working in a 'format-table',but still not in 'convertto-html'.
Here's the code so far:
function get-relative($infile) {
begin { $return_hash=#{} }
process {
$relative_path=($_|resolve-path -Relative)
$filehash=($_| Get-FileHash -Algorithm sha1).hash
$return_hash.add($relative_path, $filehash)
}
end { return $return_hash }
}
And to call it with a formatter:
$table_format = #{Expression={$_.Name} ; Label="Filename"}, #{Expression={$_.Value} ; Label="CHECKSUM(SHA1)"}
dir|get-relative|format-table $table_format
This gives:
Filename CHECKSUM(SHA1)
-------- --------------
.\goodbye.txt DA39A3EE5E6B4B0D3255BFEF95601890AFD80709
.\hello.txt 88A5B867C3D110207786E66523CD1E4A484DA697
But if I shove that through a 'convertto-html', weirdness ensues. (I guess this is because the output from 'format-table' is just a string by now....)
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>HTML TABLE</title>
</head><body>
<table>
<colgroup><col/><col/><col/><col/><col/><col/></colgroup>
<tr><th>ClassId2e4f51ef21dd47e99d3c952918aff9cd</th><th>pageHeaderEntry</th><th>pageFooterEntry</th><th>autosizeInfo</th><th>shapeInfo</th><th>
groupingEntry</th></tr>
<tr><td>033ecb2bc07a4d43b5ef94ed5a35d280</td><td></td><td></td><td></td><td>Microsoft.PowerShell.Commands.Internal.Format.TableHeaderInfo</td><
td></td></tr>
<tr><td>9e210fe47d09416682b841769c78b8a3</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>27c87ef9bbda4f709f6b4002fa4af63c</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>27c87ef9bbda4f709f6b4002fa4af63c</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>4ec4f0187cb04f4cb6973460dfe252df</td><td></td><td></td><td></td><td></td><td></td></tr>
<tr><td>cf522b78d86c486691226b40aa69e95c</td><td></td><td></td><td></td><td></td><td></td></tr>
</table>
</body></html>

How do I access structured metadata using DocPad?

I'm evaluating DocPad at the moment to see if it will be suitable for our website amongst other things. I'm having trouble working out how to use structured metadata in eco templates. I'm pretty sure it's related to How to display Backbone nested attribute using Eco? but that's unanswered too.
My page looks like:
--- yaml
layout: 'post'
title: "Samuel Johnson's garret - an unexpected lull"
category: 'Digital Publishing'
author:
name: Author Name
page: author
email: author.name#ourdomain.co.uk
---
Unexpected free time, a chilly walk, a brown plaque leads me to
[Dr Johnson's house (http://www.drjohnsonshouse.org/) near Fleet-Street…
and the eco template like:
---
layout: default
---
<article id="post" class="post">
<h1><%= #document.title %></h1>
<h2>By: <%= #document.author.email %></h2>
<div class="post-content"><%- #content %></div>
</article>
The #document.author.email leads to the following error being logged:
TypeError: Cannot read property 'email' of undefined
How do I access that structured metadata?
thanks
Everything seems ok. When I test the same structure, the line <%= #document.author.email %> works. Maybe you have some kind of inconsistency using white spaces and tabs ? You can validate your YAML on this site : http://yamllint.com.
Personally I also use arrays of objects in metadata :
choices:
-
text: "Mercure"
feedback: "Mercure est la planète la plus proche du Soleil, elle se situe à une distance de 0,4 UA"
value: 0
-
text: "Neptune"
feedback: "C'est effectivement la planète la plus éloignée avec une distance de 30 UA."
value: 1
and it works great. Sorry for the text in French but I guess it doesn't really matter for an example.
you can see this example, it works perfectly now, i found my issue and i want to share the solution with you:
---
slides:
-
detailimage: "heliski-img.png"
mainimage: "heliski-g.jpg"
title: "Powder South Heliski Guides"
-
detailimage: "nuevos-vientos-img.png"
mainimage: "nuevos-vientos.jpg"
title: "Centro Experiencial Nuevos Vientos"
---
#full-width-slider.royalSlider.heroSlider.rsMinW
each slide in document.slides
.rsContent
img.rsImg(src='/slideshow/#{slide.mainimage}', alt='#{slide.title}')
.infoBlock.infoBlockLeftBlack.rsABlock(data-fade-effect='', data-move-offset='10', data-move-effect='bottom', data-speed='200')
p #{slide.title}
img.rsImg(src='/slideshow/#{slide.detailimage}', alt='#{slide.title}')
the important thing is the each line, it must say "in document.slides" so i can access from jade the document metadata. :D
the final render will look like this:
<div id="full-width-slider" class="royalSlider heroSlider rsMinW">
<div class="rsContent"><img src="/slideshow/heliski-g.jpg" alt="Powder South Heliski Guides" class="rsImg">
<div data-fade-effect="" data-move-offset="10" data-move-effect="bottom" data-speed="200" class="infoBlock infoBlockLeftBlack rsABlock"></div>
<p>Powder South Heliski Guides</p><img src="/slideshow/heliski-img.png" alt="Powder South Heliski Guides" class="rsImg">
</div>
<div class="rsContent"><img src="/slideshow/nuevos-vientos.jpg" alt="Centro Experiencial Nuevos Vientos" class="rsImg">
<div data-fade-effect="" data-move-offset="10" data-move-effect="bottom" data-speed="200" class="infoBlock infoBlockLeftBlack rsABlock"></div>
<p>Centro Experiencial Nuevos Vientos</p><img src="/slideshow/nuevos-vientos-img.png" alt="Centro Experiencial Nuevos Vientos" class="rsImg">
</div>
</div>