-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
page and template edge-files generate
- Loading branch information
Showing
96 changed files
with
1,210 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import fs from 'fs' | ||
import {BaseGenerator} from "./BaseGenerator"; | ||
import Application from "@ioc:Adonis/Core/Application"; | ||
import app_path from "../../helpers/app_path"; | ||
import Page from "App/Models/Page"; | ||
|
||
export default class PageGenerator extends BaseGenerator { | ||
|
||
public static directory = Application.resourcesPath('/views/altrp/pages') | ||
public static template = app_path(`altrp-templates/views/Page.stub`) | ||
|
||
|
||
async deleteFile(page: Page): Promise<void> { | ||
let fileName = this.getFilename(page) | ||
if (fs.existsSync(PageGenerator.directory + fileName)) { | ||
fs.rmSync(PageGenerator.directory + fileName); | ||
} | ||
} | ||
|
||
getFilename(page):string{ | ||
return page.guid + '.edge' | ||
} | ||
|
||
async run(page: Page) { | ||
if(! page){ | ||
return | ||
} | ||
|
||
|
||
let fileName = this.getFilename(page) | ||
if (!page.guid ) { | ||
console.error(`Page ${page.id} render error. Need more data`); | ||
return | ||
} | ||
let children_content = await page.getChildrenContent() | ||
let all_styles = await page.getAllStyles() | ||
return await this.addFile(fileName) | ||
.destinationDir(PageGenerator.directory) | ||
.stub(PageGenerator.template) | ||
.apply({ | ||
children_content, | ||
all_styles, | ||
}) | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import { parse } from 'node-html-parser' | ||
import fs from 'fs' | ||
import {BaseGenerator} from './BaseGenerator'; | ||
import Application from '@ioc:Adonis/Core/Application'; | ||
import app_path from '../../helpers/app_path'; | ||
import Template from 'App/Models/Template'; | ||
import path from 'path'; | ||
import * as _ from 'lodash' | ||
import Logger from '@ioc:Adonis/Core/Logger' | ||
|
||
export default class TemplateGenerator extends BaseGenerator { | ||
|
||
public static directory = '/views/altrp/templates' | ||
public static template = app_path(`altrp-templates/views/Template.stub`) | ||
|
||
|
||
async deleteFile(template: Template): Promise<void> { | ||
if (fs.existsSync(path.join(this.getDirectory(template),this.getFilename(template)))) { | ||
fs.rmSync(path.join(this.getDirectory(template),this.getFilename(template))); | ||
} | ||
} | ||
|
||
getDirectory(template:Template){ | ||
return Application.resourcesPath(`${TemplateGenerator.directory}/${template.currentArea?.name}`) | ||
} | ||
|
||
getFilename(template:Template):string{ | ||
return template.guid + '.edge' | ||
} | ||
|
||
async run(template: Template) { | ||
if(! template){ | ||
return | ||
} | ||
await template.load('currentArea') | ||
|
||
const styles = JSON.parse(template.styles) | ||
|
||
let all_styles = _.get(styles, 'all_styles', []) | ||
// | ||
all_styles = all_styles.join('') | ||
all_styles = parse(all_styles) | ||
if(template.guid){ | ||
await BaseGenerator.generateCssFile(template.guid, all_styles.textContent) | ||
} | ||
let fileName = this.getFilename(template) | ||
if (! template.currentArea?.name) { | ||
console.error(`Template ${template.id} render error. Need Area name`); | ||
Logger.warn(`Try Render Template without area (id: ${template.id})`) | ||
return | ||
} | ||
if (!template.guid ) { | ||
console.error(`Template ${template.id} render error. Need guid`); | ||
Logger.warn(`Try Render Template without guid (id: ${template.id})`) | ||
return | ||
} | ||
let children_content = await template.getChildrenContent() | ||
return await this.addFile(fileName) | ||
.destinationDir(this.getDirectory(template)) | ||
.stub(TemplateGenerator.template) | ||
.apply({ | ||
children_content, | ||
all_styles:'', | ||
area_name: template.currentArea?.name, | ||
}) | ||
|
||
} | ||
} |
Oops, something went wrong.