Creating custom HTML with asciidoctor - asciidoc

I'm using a CMS to publish my blog articles. I'm looking for a way to create HTML articles offline from a simple text file.
This is a piece of HTML which I normally use for my articles:
<p> We want to show how you can gather information such as the author name:</p>
<pre class="brush:java">package com.sample;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.main.Main;
public class XMLCamel {
public static void main(String[] args) throws Exception {
Main main = new Main();
}
}
class Sample extends RouteBuilder {
#Override
public void config() throws Exception {
from("file:/usr/data/files?noop=true")
.split(xpath("//catalog/book/author/text()")).to("stream:out");
}
}</pre>
<p>The above route will print the author names according to the <strong>XPath</strong> query: //catalog/book/author/text()</p>
<p>The authors will be sent to the Stream.out so you will see them on the console once you run the code.</p>
<p><strong>Result:</strong></p>
<p><strong>John Smith Sally Joy</strong></p>
As you can see I use some customizations to wrap code (pre class etc.). Is it something which can be easily done with Asciidoctor ? I'm new to Asciidoctor and just wonder if it's worth investing time in learning it for this purpose.
Thanks!

To answer the question, yes it's possible. However, for something trivial like this the output from asciidoctor ootb along with the highlighter of choice may work fine for what you're doing.
Should you need to customize things you'll need to creat a custom backend. As the docs for creating a custom backend haven't been finished yet this mailing list post should help.

In addition to LightGuard's advanced answer it's worth mentioning that you can use ++++ to add custom HTML to the output.
++++<h1>hello</h1>++++
will simply generate
<h1>hello</h1>

Related

Validate and out put uploaded files with spatie/laravel-data package

I'm trying to use Spatie/Laravel-data package for the first time, and most importantly this is for an interview assignment. I really wanted to this work to be more attractive to the interviewer so instead of just using the normal way I wanted to use Spatie/Laravel-data package.
So, My problem is I did follow their introduction videos and I could replicate all the things in the video but in any of the tutorials or materials I couldn't find how to use DTOs with file uploading. Specially I want to upload multiple files via API
This is what I have at the moment.
class DamageReportData extends Data
{
public string $name;
#[Email]
public string $email;
public string $description;
public float $latitude;
public float $longitude;
// #[Rule(['mimes:jpeg,jpg,png,gif,csv,txt,pdf|max:2048'])]
// public UploadedFile $uploadedFiles;
public ?Carbon $date;
}
until I keep commenting on those two lines it all works perfectly. otherwise, I'm getting an error
Error: Typed property App\Data\DamageReportData::$uploadedFiles must not be accessed before initialization in file D:\xampp\htdocs\fixico\vendor\spatie\laravel-data\src\Transformers\DataTransformer.php on line 73
If someone can guide me on how to do this properly will be a huge advantage for me and I really appreciate your help.

How Do you make a public TMPText unity C#

I am new to unity and I was wondering if there is any way to call a Public TextMeshPro Because I have been trying to make a score timer Current Script For example I use
public Text ScoreText; . So is there any way to work to do something like Public Tmp_Text ScoreText; or something Like That? (Sorry I am pretty new)
I wish you good luck on your journey of learning unity.
There are several things you need to keep in mind to solve your problems.
Follow tutorials and learn from them.
Check unity api to get references on how specific modules/commands function.
In your case that would be this reference.
Here's the shortest way to do what you want:
add using TMPro;to the very top of your script
declare your variable public TextMeshProUGUI scoreText
use your variable in code to set text;
void AddPoints(int pointsEarned)
{
currentScore += pointsEarned;
scoreText.SetText(currentScore.ToString());
}

Caching catalogues from Symfony2 Translation component

I have been trying to figure out another way of handling i18n within FuelPHP (see here).
I decided to import the Symfony2 Translation component (using composer) to Fuel as a vendor and manage i18n with xliff files.
Here is my (simplified) code:
use \Symfony\Component\Translation\Translator;
use \Symfony\Component\Translation\MessageSelector;
use \Symfony\Component\Translation\Loader\XliffFileLoader;
...
class I18N
{
private static $translator = NULL;
....
public static function get($key)
{
# Load and configure the translator
self::$translator = new Translator('en_GB', new MessageSelector());
self::$translator->addLoader('xliff', new XliffFileLoader());
self::$translator->addResource('xliff', 'path/to/xliff/file', 'en');
# Get the translation
$translation = self::$translator->trans($key, $params);
# Return the translation
return $translation;
}
}
So at first I thought that was working great since I was testing it on a very small xliff file but now that I've generated the complete xliff catalogue (about 1400 entries) for my entire application, each request is really slow.
So the question is, is there a way to cache translations when using the Translation component the same way the whole Symfony2 Framework caches it natively?
The Translator Class from the FrameworkBundle has a constructor that accepts options in which you can define the cache_dir. Anyway I can achieve that using the Translation component?
Thanks for any help on that matter.
So what I did was to generate my own cache from xliff files, if it doesn't exist, which is nothing more than the translations as a php array and make the Translator Component load resources as ArrayLoader instead of XliffFileLoader. It's lightning fast now. Thanks to Touki in the comments for your interest.

MVC3 Url.Action() - Is there a simpiler way to write links in MVC3?

I'm working on a site and I'm new to MVC3 Framework. I'm coming from a place where writing URL's is very simple href="some/web/page.html" but now with the MVC3 URLs are more complex.
By complex I mean are more involved to write. href="#Url.Action("index", "Home")" that requires hitting the shift key multiple times which is tiresome and redundant for someone coming from href="some/web/page.html" only hitting shift twice for that.
And the site I'm working on is using areas which adds another level of complexity to the URL.
href="#Url.Action("index", "area", new { area = "some_area})"
I'm working on a 100+ page site. Writing these #Action.Url() is becoming boring and irritating. Is there something I can do to cut out the redundancy?
You could try using T4MVC, other than that there isn't really much you can do.
You can read it's documentation here.
You can make some extension methods like Kazi explains here :
http://weblogs.asp.net/rashid/archive/2009/04/01/asp-net-mvc-best-practices-part-1.aspx
Something like this :
public static class UrlHelperExtension
{
public static string Home(this UrlHelper helper)
{
return helper.Content("~/");
}
}
You can also use David Ebbo MVC T4 template for generating helper methods :
http://blogs.msdn.com/b/davidebb/archive/2009/06/01/a-buildprovider-to-simplify-your-asp-net-mvc-action-links.aspx
http://blogs.msdn.com/b/davidebb/archive/2009/06/26/the-mvc-t4-template-is-now-up-on-codeplex-and-it-does-change-your-code-a-bit.aspx
http://mvccontrib.codeplex.com/wikipage?title=T4MVC_doc&referringTitle=T4MVC
Hope this helps

Question - Should I use SPItemReceiver or SPEmailEventReceiver

I have custom SharePoint Document Library which I use to upload spreadsheet data into a database. When a spreadsheet is uploaded, the SPItemReceiver triggers, and upload the data.
Now, I would like to add an incoming email feature to the document library.
My question is...after the document library has received the spreadsheet by email. Should I use the override-able method EmailReceived of the SPEmailEventReceiver to process the data in the spreadsheet or still use the SPItemReceiver?
I gather I could use either, but I would like to know your opinion which is better and why.
Thanks in advance
You should use SPEmailEventReceiver to process the data. This will make it easy for you to maintain your code and debug. Below is the sample code to process the data. In this code itself, you can include the code to upload the data into database.
public class EmailHandler: SPEmailEventReceiver
{
public override void EmailReceived(
SPList objList,
SPEmailMessage objMessage,
string strReceiverData)
{
SPListItem objListItem = objList.Items.Add();
objListItem["Title"] = objMessage.Headers["Subject"];
objListItem["Body"] = objMessage.HtmlBody;
objListItem.Update();
}
}

Resources