How to read html files on Vapor with Leaf when not using the tau version? - swift

There was a version of Leaf that I was using to load .html files instead of .leaf ones from my Vapor project, which would make syntax coloring for those same files done automatically.
The version of Leaf was 4.0.0-tau.1 and the one for LeafKit was 1.0.0-tau.1.1
When using this particular version, I could setup leaf in the configure.swift file this way:
/// Change the classic .leaf extension to .html for the syntax
/// coloring option of Xcode to work each time the app is being load up.
fileprivate func leaf(_ app: Application) {
if !app.environment.isRelease {
LeafRenderer.Option.caching = .bypass // Another issue from the update
}
let detected = LeafEngine.rootDirectory ?? app.directory.viewsDirectory
LeafEngine.rootDirectory = detected
LeafEngine.sources = .singleSource(
NIOLeafFiles(fileio: app.fileio,
limits: .default,
sandboxDirectory: detected,
viewDirectory: detected,
defaultExtension: "html"))
app.views.use(.leaf)
}
In this code, the LeafRenderer.Option.caching = .bypass and the code used with LeafEngine do not work anymore since having updated Leaf to 4.1.3 and LeafKit to 1.3.1.
How can I successfully make this code work as before with the updated Leaf and LeafKit frameworks?

You can use this Xcode plugin:
https://github.com/OmranK/VaporLeafPlugIn
It adds Vapor Leaf language support to Xcode IDE. Provides syntax highlighting for Leaf tags as well as HTML tags with auto-indentation all together.
At the moment the plugin supports Xcode up to 13.2 beta. Future Xcode versions will require small update (add new DVTPlugInCompatibilityUUID) but it can be easily handled even on already installed plugin.

Related

Identifier expected.ts(1003) with Alpinejs and Astro

I'm using Aplinejs (3.11.1) with Astro.build (2.0.13) and have the following on a div
x-on:click.outside="shownav = false"
I'm getting the following error in VS Code (1.74.3) on the "."
Identifier expected.ts(1003)
I'm new to VS Code, Alpine and Astro, so I'm not sure how to get rid of this error. Can someone advise? I'm using TypeScript 4.9.5.
Separate but related, for anyone getting the following error on "outside":
Property 'outside' does not exist on type 'HTMLAttributes'.ts(2322)
I sorted that by adding this to src/custom-attributes.d.ts
declare namespace astroHTML.JSX {
interface HTMLAttributes {
outside?: string;
}}
Version of the Astro VS Code extension lower than 0.29.0 don't support Alpine correctly. (See this issue)
At the time of writing, 0.29.0 is only available in Pre-release. You can update to it by pressing the Switch to Pre-Release button on the extension page.
Screenshot of the extension page

Import SQLClient into existing Xcode (Swift) project

I've never messed with iOS so this is all new to me. I'm trying to import SQLClient into an an existing Xcode project. (I need to fire off an INSERT from the iOS app.)
https://github.com/martinrybak/SQLClient
I've tried both installation methods listed by Martin via cocoapods and manual but I can't get either to work.
For option #1) everything worked fine until I tried pod install and was met with
Analyzing dependencies
[!] The dependency SQLClient (~> 0.1.3) is not used in any concrete target.
I was expecting the command to produce a file named SQLClient.xcworkspace. I wasn't sure if this new xcworkspace file was meant to replace my main project xcode file. But since it didn't work, I moved onto option #2.
For option #2 I wasn't sure where to put the contents. (Does Martin mean /SQLClient/SQLClient/SQLClient/SQLClient or /SQLClient/SQLClient/SQLClient?)
Was I supposed to copy just the files or the whole folder?
Do the contents go into my project at the same level as my original xcode project file or in a subfolder?
I've tried a couple variations but I admittedly don't know where the SQLClient files/folders should be placed in relation to my other project files.
I've tried messing with my bridge file as well but I've been unable to properly load it.
I have some time (2 days) to figure this out so I'm willing to learn but I need some guidance.
Here's a pic of my existing Xcode project and latest attempt to import SQLClient.
It looks like you have all the files in your project correctly.
Things to check.
If you said yes to create the bridge file when you dragged the object-c file into the project then you just need to add #import "SQLClient.h" to the bridge file. If you created the bridge file manually make sure it is added to Build Settings - Objective-C Bridging Header.
Make sure in your target - general - linked framework and libraries you have libiconv.tb and libfreetds.a
Swift 3
class testViewController: UIViewController, SQLClientDelegate {
// Handles errors from the SQLClient
func error(_ error: String!, code: Int32, severity: Int32) {
print("\(error!) \(code) \(severity)")
}
//MARK: Lifecyle
override func viewDidLoad() {
super.viewDidLoad()
let client = SQLClient.sharedInstance()!
client.delegate = self
client.connect("ServerNameOrIP", username: "cool", password: "cool", database: "database") { success in
client.execute("SELECT * FROM table", completion: { (_ results: ([Any]?)) in
for table in results as! [[[String:AnyObject]]] {
for row in table {
for (columnName, value) in row {
print("\(columnName) = \(value)")
}
}
}
client.disconnect()
})
}
}
}
Created a sample project here
I was able to get installation option #1 working after changing the pod file to include a target.
target "TargetName" do
pod 'SQLClient', '~> 0.1.3'
end
I downloaded SQLClient manually and it worked for me.You will get the steps to connect from swift project from here - https://github.com/salmasumona/Call-SP-from-iOS-project-using-SQLClient
SWIFT 5
enter image description hereThe best way to use Obj-C in a Swift project is to use a bridging header file, what I did with SQLCLient was to drag and drop the files from SQL client and then Xcode will ask if you want to create a bridging header file, select yes.
Inside the bridging header file, import "SQLClient.h", from here you can build the project and everything should compile. You can then create a SQLClient object like you did above and inside the .connect you make the sure the completion handler checks if it was successful then inside the closure you can call client.execute and from here if you put a SQL command as a string and use data as a variable inside the .execute completion block, if you print this data variable you will return all of the data from the SQL Server. It returns in JSON, so from here you can convert using JSON Serialization.
If you have any questions, please feel free to message me and I will return a screenshot of what my code looked like so that it may help you!

Copy a folder with Smartsheet API - Java SDK 2.0.5

I am trying to copy a folder with the Smartsheet API 2.0 (Java SDK 2.0.5).
Unfortunately the folders and sheets (all sub folders/sheets too) are copied but the sheet data is missing.
I get no errors everything works fine.
I tried several variants of the optional include parameters the ".ALL", "null", ...
This is the example code and the used environment:
Netbeans IDE 8.2
smartsheet-sdk-java-2.0.5.jar (with maven)
// Optional params
EnumSet includes = EnumSet.complementOf(EnumSet.of(FolderCopyInclusion.ALL)); // Copy all fields!
EnumSet skipRemap = EnumSet.noneOf(FolderRemapExclusion.class); // Remap all fields
// Specify destination.
ContainerDestination destination = new ContainerDestination.AddContainerDestinationBuilder()
.setDestinationType(DestinationType.FOLDER)
.setDestinationId(targetFolder.getId())
.setNewName(folder.getName())
.build();
smartsheet.folderResources().copyFolder(folder.getId(), destination, includes, skipRemap);
What am i doing wrong? Thanks a lot for your help.
Perhaps try changing this line:
EnumSet includes = EnumSet.complementOf(EnumSet.of(FolderCopyInclusion.ALL)); // Copy all fields!
To this instead:
EnumSet includes = EnumSet.of(FolderCopyInclusion.ALL);
(I'm not a Java expert, but the change I've suggested is consistent with the code example in the Smartsheet API Documentation.)

What happened to AddExportedObject?

we have source code from a long time ago .NET 2.0 which looks like:
DirectoryCatalog catalog =
new DirectoryCatalog(Path.Combine(Path.Combine(applicationDirectory, providersDirectory), providerSubdirectory));
CompositionContainer container = new CompositionContainer(catalog);
CompositionBatch batch = new CompositionBatch();
batch.AddPart(this);
batch.AddExportedObject(container);
container.Compose(batch);
This has worked fine for years, but after upgrading visual studio and the framework to .NET 4.0, the call to AddExportedObject no longer seems to be supported by MEF.
As you can read here,
While CompositionBatch itself does not contain an AddExportedObject<T>
there is an extension method for it. The extension methods are in the
root System.ComponentModel.Composition namespace so ensure you are
including that in your file's using statements. If you cannot get the
extension method to work you can always call the method directly on
AttributedModelServices.

Can't save state in windows 8 [ Error The type or namespace name 'Common'

Can't save state in windows 8
{
Error The type or namespace name 'Common' ...does not exist in the namespace 'ProjectName' (are you missing an assembly reference?)
}
Everything below is the default code in my App.Xaml.cs file the only line I added was
ProjectNameSpace.Common.SuspensionManager.RegisterFrame(rootFrame, "appframe");
which is from the windows 8 tutorial here and I have followed part 1 before attempting this http://msdn.microsoft.com/en-us/library/windows/apps/hh986968.aspx. I have it working in another project that has the same references and using statements. There is only one namespace in the project and I even Rebuilt/Cleaned. Does anybody have any extra information?
protected override void OnLaunched(LaunchActivatedEventArgs args)
{
Frame rootFrame = Window.Current.Content as Frame;
if (rootFrame == null)
{
rootFrame = new Frame();
ProjectNameSpace.Common.SuspensionManager.RegisterFrame(rootFrame, "appframe");
if (args.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
}
Window.Current.Content = rootFrame;
EDIT:
The problem was that I needed to add a basic page in my blank template. This auto generates some classes needed to do basic functionality. Below is a screenshot of the minimum items that the common folder needs to contain.
Do you have the Common folder present in your project? This folder is usually included in the Visual Studio 2012 App project templates (except the Blank App template) which contains a bunch of classes with boilerplate code for layout, styles and other functionality.
If you created your project with a Blank App template, you may not have this. To get it included, create a new Basic Page (Right-click on your Project > Add > New Item > (Visual C#)* > Basic Page), and Visual Studio will ask if you would like to create these files.
*I'm not sure what this is for VB .NET or WinJS, but I assume it would be the same structure.