initial
This commit is contained in:
commit
28e103f351
6
.idea/encodings.xml
generated
Normal file
6
.idea/encodings.xml
generated
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="Encoding">
|
||||||
|
<file url="PROJECT" charset="UTF-8" />
|
||||||
|
</component>
|
||||||
|
</project>
|
13
.idea/ginpongo2v3.iml
generated
Normal file
13
.idea/ginpongo2v3.iml
generated
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="WEB_MODULE" version="4">
|
||||||
|
<component name="Go" enabled="true" />
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/.tmp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/temp" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/tmp" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
8
.idea/modules.xml
generated
Normal file
8
.idea/modules.xml
generated
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/ginpongo2v3.iml" filepath="$PROJECT_DIR$/.idea/ginpongo2v3.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
18
.idea/mongoSettings.xml
generated
Normal file
18
.idea/mongoSettings.xml
generated
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="MongoConfiguration">
|
||||||
|
<option name="serverConfigurations">
|
||||||
|
<list>
|
||||||
|
<ServerConfiguration>
|
||||||
|
<option name="label" value="localhost" />
|
||||||
|
<option name="serverUrls">
|
||||||
|
<list>
|
||||||
|
<option value="localhost:27017" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</ServerConfiguration>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
<option name="shellPath" value="/usr/bin/mongo" />
|
||||||
|
</component>
|
||||||
|
</project>
|
263
.idea/workspace.xml
generated
Normal file
263
.idea/workspace.xml
generated
Normal file
@ -0,0 +1,263 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ChangeListManager">
|
||||||
|
<list default="true" id="71dc9469-6b67-411b-a0d9-892b3fd3e790" name="Default" comment="" />
|
||||||
|
<ignored path="$PROJECT_DIR$/.tmp/" />
|
||||||
|
<ignored path="$PROJECT_DIR$/temp/" />
|
||||||
|
<ignored path="$PROJECT_DIR$/tmp/" />
|
||||||
|
<option name="EXCLUDED_CONVERTED_TO_IGNORED" value="true" />
|
||||||
|
<option name="TRACKING_ENABLED" value="true" />
|
||||||
|
<option name="SHOW_DIALOG" value="false" />
|
||||||
|
<option name="HIGHLIGHT_CONFLICTS" value="true" />
|
||||||
|
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
|
||||||
|
<option name="LAST_RESOLUTION" value="IGNORE" />
|
||||||
|
</component>
|
||||||
|
<component name="FileEditorManager">
|
||||||
|
<leaf>
|
||||||
|
<file leaf-file-name="render.go" pinned="false" current-in-tab="false">
|
||||||
|
<entry file="file://$PROJECT_DIR$/render.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="198">
|
||||||
|
<caret line="11" column="0" lean-forward="false" selection-start-line="11" selection-start-column="0" selection-end-line="11" selection-end-column="0" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#21#108#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
<file leaf-file-name="README.md" pinned="false" current-in-tab="true">
|
||||||
|
<entry file="file://$PROJECT_DIR$/README.md">
|
||||||
|
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
|
||||||
|
<state split_layout="SPLIT">
|
||||||
|
<first_editor relative-caret-position="746">
|
||||||
|
<caret line="50" column="3" lean-forward="true" selection-start-line="50" selection-start-column="3" selection-end-line="50" selection-end-column="3" />
|
||||||
|
<folding>
|
||||||
|
<marker date="1509028204145" expanded="true" signature="156:279" ph="..." />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="319:1139" ph="{...}" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:493" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:569" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:587" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:644" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:663" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="704:756" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="704:785" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="704:831" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="902:1078" ph="{...}" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="902:1096" ph="{...}" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="902:1139" ph="{...}" />
|
||||||
|
</folding>
|
||||||
|
</first_editor>
|
||||||
|
<second_editor />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</file>
|
||||||
|
</leaf>
|
||||||
|
</component>
|
||||||
|
<component name="FileTemplateManagerImpl">
|
||||||
|
<option name="RECENT_TEMPLATES">
|
||||||
|
<list>
|
||||||
|
<option value="Go File" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="GOROOT" path="/usr/lib/go" />
|
||||||
|
<component name="IdeDocumentHistory">
|
||||||
|
<option name="CHANGED_PATHS">
|
||||||
|
<list>
|
||||||
|
<option value="$PROJECT_DIR$/render.go" />
|
||||||
|
<option value="$PROJECT_DIR$/README.md" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="JsBuildToolGruntFileManager" detection-done="true" sorting="DEFINITION_ORDER" />
|
||||||
|
<component name="JsBuildToolPackageJson" detection-done="true" sorting="DEFINITION_ORDER" />
|
||||||
|
<component name="JsGulpfileManager">
|
||||||
|
<detection-done>true</detection-done>
|
||||||
|
<sorting>DEFINITION_ORDER</sorting>
|
||||||
|
</component>
|
||||||
|
<component name="ProjectFrameBounds" extendedState="6">
|
||||||
|
<option name="y" value="27" />
|
||||||
|
<option name="width" value="1910" />
|
||||||
|
<option name="height" value="1053" />
|
||||||
|
</component>
|
||||||
|
<component name="ProjectView">
|
||||||
|
<navigator currentView="ProjectPane" proportions="" version="1">
|
||||||
|
<flattenPackages />
|
||||||
|
<showMembers />
|
||||||
|
<showModules />
|
||||||
|
<showLibraryContents />
|
||||||
|
<hideEmptyPackages />
|
||||||
|
<abbreviatePackageNames />
|
||||||
|
<autoscrollToSource />
|
||||||
|
<autoscrollFromSource />
|
||||||
|
<sortByType />
|
||||||
|
<manualOrder />
|
||||||
|
<foldersAlwaysOnTop value="true" />
|
||||||
|
</navigator>
|
||||||
|
<panes>
|
||||||
|
<pane id="Scope" />
|
||||||
|
<pane id="ProjectPane">
|
||||||
|
<subPane>
|
||||||
|
<expand>
|
||||||
|
<path>
|
||||||
|
<item name="ginpongo2v3" type="b2602c69:ProjectViewProjectNode" />
|
||||||
|
<item name="ginpongo2v3" type="462c0819:PsiDirectoryNode" />
|
||||||
|
</path>
|
||||||
|
</expand>
|
||||||
|
<select />
|
||||||
|
</subPane>
|
||||||
|
</pane>
|
||||||
|
<pane id="Scratches" />
|
||||||
|
</panes>
|
||||||
|
</component>
|
||||||
|
<component name="PropertiesComponent">
|
||||||
|
<property name="settings.editor.selected.configurable" value="configurable.group.tools" />
|
||||||
|
<property name="configurable.Global.libraries.is.expanded" value="true" />
|
||||||
|
<property name="configurable.Global.GOPATH.is.expanded" value="true" />
|
||||||
|
<property name="nodejs_interpreter_path" value="/usr/bin/node" />
|
||||||
|
<property name="configurable.Project.GOPATH.is.expanded" value="true" />
|
||||||
|
<property name="WebServerToolWindowFactoryState" value="false" />
|
||||||
|
<property name="go.sdk.automatically.set" value="true" />
|
||||||
|
<property name="DefaultGoTemplateProperty" value="Go File" />
|
||||||
|
<property name="HbShouldOpenHtmlAsHb" value="" />
|
||||||
|
</component>
|
||||||
|
<component name="RunDashboard">
|
||||||
|
<option name="ruleStates">
|
||||||
|
<list>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="ConfigurationTypeDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
<RuleState>
|
||||||
|
<option name="name" value="StatusDashboardGroupingRule" />
|
||||||
|
</RuleState>
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</component>
|
||||||
|
<component name="RunManager">
|
||||||
|
<configuration default="true" type="GoApplicationRunConfiguration" factoryName="Go Application">
|
||||||
|
<module name="" />
|
||||||
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
|
<go_parameters value="-i" />
|
||||||
|
<kind value="FILE" />
|
||||||
|
<filePath value="$PROJECT_DIR$" />
|
||||||
|
<package value="github.com/dalu/ginpongo2v3" />
|
||||||
|
<directory value="$PROJECT_DIR$" />
|
||||||
|
</configuration>
|
||||||
|
<configuration default="true" type="GoTestRunConfiguration" factoryName="Go Test">
|
||||||
|
<module name="" />
|
||||||
|
<working_directory value="$PROJECT_DIR$" />
|
||||||
|
<go_parameters value="-i" />
|
||||||
|
<framework value="gotest" />
|
||||||
|
<kind value="DIRECTORY" />
|
||||||
|
<package value="github.com/dalu/ginpongo2v3" />
|
||||||
|
</configuration>
|
||||||
|
</component>
|
||||||
|
<component name="ShelveChangesManager" show_recycled="false">
|
||||||
|
<option name="remove_strategy" value="false" />
|
||||||
|
</component>
|
||||||
|
<component name="SvnConfiguration">
|
||||||
|
<configuration />
|
||||||
|
</component>
|
||||||
|
<component name="TaskManager">
|
||||||
|
<task active="true" id="Default" summary="Default task">
|
||||||
|
<changelist id="71dc9469-6b67-411b-a0d9-892b3fd3e790" name="Default" comment="" />
|
||||||
|
<created>1509019810875</created>
|
||||||
|
<option name="number" value="Default" />
|
||||||
|
<option name="presentableId" value="Default" />
|
||||||
|
<updated>1509019810875</updated>
|
||||||
|
<workItem from="1509019812180" duration="8386000" />
|
||||||
|
</task>
|
||||||
|
<servers />
|
||||||
|
</component>
|
||||||
|
<component name="TimeTrackingManager">
|
||||||
|
<option name="totallyTimeSpent" value="8386000" />
|
||||||
|
</component>
|
||||||
|
<component name="ToolWindowManager">
|
||||||
|
<frame x="0" y="27" width="1920" height="1053" extended-state="6" />
|
||||||
|
<editor active="true" />
|
||||||
|
<layout>
|
||||||
|
<window_info id="Project" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" show_stripe_button="true" weight="0.24973261" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Docker" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Event Log" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
|
||||||
|
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.32968238" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="false" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Mongo Explorer" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Terminal" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Favorites" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="-1" side_tool="true" content_ui="tabs" />
|
||||||
|
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
|
||||||
|
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="SLIDING" type="SLIDING" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
|
||||||
|
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
||||||
|
</layout>
|
||||||
|
</component>
|
||||||
|
<component name="TypeScriptGeneratedFilesManager">
|
||||||
|
<option name="version" value="1" />
|
||||||
|
</component>
|
||||||
|
<component name="VcsContentAnnotationSettings">
|
||||||
|
<option name="myLimit" value="2678400000" />
|
||||||
|
</component>
|
||||||
|
<component name="XDebuggerManager">
|
||||||
|
<breakpoint-manager />
|
||||||
|
<watches-manager />
|
||||||
|
</component>
|
||||||
|
<component name="editorHistoryManager">
|
||||||
|
<entry file="file://$PROJECT_DIR$/render.go">
|
||||||
|
<provider selected="true" editor-type-id="text-editor">
|
||||||
|
<state relative-caret-position="198">
|
||||||
|
<caret line="11" column="0" lean-forward="false" selection-start-line="11" selection-start-column="0" selection-end-line="11" selection-end-column="0" />
|
||||||
|
<folding>
|
||||||
|
<element signature="e#21#108#0" expanded="true" />
|
||||||
|
</folding>
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
<entry file="file://$PROJECT_DIR$/README.md">
|
||||||
|
<provider selected="true" editor-type-id="split-provider[text-editor;markdown-preview-editor]">
|
||||||
|
<state split_layout="SPLIT">
|
||||||
|
<first_editor relative-caret-position="746">
|
||||||
|
<caret line="50" column="3" lean-forward="true" selection-start-line="50" selection-start-column="3" selection-end-line="50" selection-end-column="3" />
|
||||||
|
<folding>
|
||||||
|
<marker date="1509028204145" expanded="true" signature="156:279" ph="..." />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="319:1139" ph="{...}" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:493" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:569" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:587" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:644" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="424:663" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="704:756" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="704:785" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="704:831" ph="/.../" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="902:1078" ph="{...}" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="902:1096" ph="{...}" />
|
||||||
|
<marker date="1509028204145" expanded="true" signature="902:1139" ph="{...}" />
|
||||||
|
</folding>
|
||||||
|
</first_editor>
|
||||||
|
<second_editor />
|
||||||
|
</state>
|
||||||
|
</provider>
|
||||||
|
</entry>
|
||||||
|
</component>
|
||||||
|
<component name="masterDetails">
|
||||||
|
<states>
|
||||||
|
<state key="ScopeChooserConfigurable.UI">
|
||||||
|
<settings>
|
||||||
|
<splitter-proportions>
|
||||||
|
<option name="proportions">
|
||||||
|
<list>
|
||||||
|
<option value="0.2" />
|
||||||
|
</list>
|
||||||
|
</option>
|
||||||
|
</splitter-proportions>
|
||||||
|
</settings>
|
||||||
|
</state>
|
||||||
|
</states>
|
||||||
|
</component>
|
||||||
|
</project>
|
57
README.md
Normal file
57
README.md
Normal file
@ -0,0 +1,57 @@
|
|||||||
|
# pongo2.v3 for go-gin
|
||||||
|
|
||||||
|
- using templatesets
|
||||||
|
- debug aware
|
||||||
|
- basepath suppliable
|
||||||
|
|
||||||
|
## How to use
|
||||||
|
|
||||||
|
main.go
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/dalu/ginpongo2v3"
|
||||||
|
"gopkg.in/flosch/pongo2.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
func main () {
|
||||||
|
r := gin.Default()
|
||||||
|
|
||||||
|
pr := ginpongo2v3.New("default", "templates", gin.IsDebugging())
|
||||||
|
// default is the TemplateSet name
|
||||||
|
// templates is the basePath
|
||||||
|
// gin.IsDebugging() means if gin is in debug/dev mode then templates
|
||||||
|
// will always be reloaded from disk, otherwise from cache and never
|
||||||
|
// reloaded.
|
||||||
|
ginpongo2v3.Suffix = ".html.twig" // this is default
|
||||||
|
// when ever you render something reference it by prefix
|
||||||
|
// e.g. frontpage = frontpage.html.twig
|
||||||
|
|
||||||
|
r.HTMLRender = pr
|
||||||
|
|
||||||
|
r.GET("/", func(c *gin.Context) {
|
||||||
|
// only pongo2.Context or nil is accepted
|
||||||
|
ctx := make(pongo2.Context)
|
||||||
|
ctx["greeting"] = "hello world"
|
||||||
|
c.HTML(200, "frontpage", ctx)
|
||||||
|
})
|
||||||
|
|
||||||
|
r.Run(":8080")
|
||||||
|
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
templates/frontpage.html.twig
|
||||||
|
|
||||||
|
```twig
|
||||||
|
{{greeting}}
|
||||||
|
```
|
||||||
|
|
||||||
|
`hello world`
|
||||||
|
|
||||||
|
## inspirations and thanks
|
||||||
|
|
||||||
|
https://github.com/rainbowism/gin-pongo2
|
52
render.go
Normal file
52
render.go
Normal file
@ -0,0 +1,52 @@
|
|||||||
|
package ginpongo2v3
|
||||||
|
|
||||||
|
import (
|
||||||
|
"net/http"
|
||||||
|
|
||||||
|
"github.com/gin-gonic/gin/render"
|
||||||
|
"gopkg.in/flosch/pongo2.v3"
|
||||||
|
)
|
||||||
|
|
||||||
|
var Suffix = ".html.twig"
|
||||||
|
|
||||||
|
type Pongo struct {
|
||||||
|
set *pongo2.TemplateSet
|
||||||
|
}
|
||||||
|
|
||||||
|
func (p *Pongo) Instance(name string, data interface{}) render.Render {
|
||||||
|
r := new(PongoRenderer)
|
||||||
|
tpl, e := p.set.FromCache(name + Suffix)
|
||||||
|
if e != nil {
|
||||||
|
panic(e)
|
||||||
|
}
|
||||||
|
r.tpl = tpl
|
||||||
|
r.data = data
|
||||||
|
return r
|
||||||
|
}
|
||||||
|
|
||||||
|
type PongoRenderer struct {
|
||||||
|
tpl *pongo2.Template
|
||||||
|
data interface{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *PongoRenderer) Render(w http.ResponseWriter) error {
|
||||||
|
if r.data == nil {
|
||||||
|
r.data = make(pongo2.Context)
|
||||||
|
}
|
||||||
|
d := pongo2.Context(r.data.(pongo2.Context))
|
||||||
|
return r.tpl.ExecuteWriter(d, w)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *PongoRenderer) WriteContentType(w http.ResponseWriter) {
|
||||||
|
if v := w.Header().Get("content-type"); len(v) == 0 {
|
||||||
|
w.Header().Set("content-type", "text/html; charset=utf8")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func New(name, basepath string, debug bool) *Pongo {
|
||||||
|
p := new(Pongo)
|
||||||
|
p.set = pongo2.NewSet(name)
|
||||||
|
p.set.Debug = debug
|
||||||
|
p.set.SetBaseDirectory(basepath)
|
||||||
|
return p
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user