Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add a pure lua configure method #23

Closed
lancelijade opened this issue Jul 18, 2016 · 7 comments
Closed

add a pure lua configure method #23

lancelijade opened this issue Jul 18, 2016 · 7 comments

Comments

@lancelijade
Copy link

Hi Aapo,

I'm trying use OpenResty's resty command line tools to test your module, and found I cannot setup a template_location or template_root in the nginx's config file ( or maybe I missed something ).

But, anyway, I think set a pure lua method to setup templete_root is reasonable, and may make the template more easy to use.

Here is my hack, quite ugly but useful for me:

    local root = vars and (var.template_root or var.document_root) or prefix
-- hack: injected lua operated template.tpl_root as template root
    if template.tpl_root then root = template.tpl_root end
-- hack end
    if sub(root, -1) == "/" then root = sub(root, 1, -2) end

and in my code:

local template = require "resty.template"
template.tpl_root = "/some/path/to/template"
template.render("view.html", "hello world")

How do you think this?

Lance

@lancelijade
Copy link
Author

The example code attached to show usage is wrong, but I think you can understand it. :P

@lancelijade
Copy link
Author

Ok, after I read template.load() https://github.com/bungle/lua-resty-template#templateload again, I can understand you design. But I still think injecting a configurable variable into loadngx() is useful, because it quite easier compared to reimplement template.load() and maybe readfile().

@bungle
Copy link
Owner

bungle commented Jul 19, 2016

@lancelijade thanks, I'm currently on vacation, but I will look this when I come back (about two weeks).

@bungle
Copy link
Owner

bungle commented Nov 15, 2016

@lancelijade,

Sorry that you have been waiting this for so long. At first it seems to be a good way to do it like you did, but I worry a bit if you have say several web applications, and they both set:

-- web app 1
template.root = '/web/one'
-- web app 2
template.root = '/web/two'

In some weird edge case this could lead to web app 2 using template root of web app 1 or vise versa (e.g. you yield the worker on web app 1, and then web app 2 sets the root, and then you load a template on web app 1).

@bungle
Copy link
Owner

bungle commented Nov 15, 2016

In general I think that these load functions are somewhat wrongly designed. They do too many things. But it is hard to change that without making breaking changes.

@bungle
Copy link
Owner

bungle commented Sep 27, 2019

I think we just need an instance, e.g. make template.new to allow you pass the parameters, so that you don't mix them with globals.

bungle added a commit that referenced this issue Feb 20, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 20, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 20, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()` and `template.new(options)`
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function` (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 21, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 24, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 24, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
bungle added a commit that referenced this issue Feb 24, 2020
### Added
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (#36)

### Changed
- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (#32)

### Fixed
- Wrong template returned when using multiple server blocks (#25)
- Add a pure lua configure method (#23, #7)
@bungle
Copy link
Owner

bungle commented Feb 24, 2020

2.0 now has:

template.root=<path>
template.location=<location>

So I am closing this. The template.new to create a new instance is also implemented.

@bungle bungle closed this as completed Feb 24, 2020
olegrok pushed a commit to tarantool/template that referenced this issue May 9, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
olegrok pushed a commit to tarantool/template that referenced this issue May 9, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
olegrok pushed a commit to tarantool/template that referenced this issue May 9, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
olegrok pushed a commit to tarantool/template that referenced this issue Oct 1, 2020
- Support for `template.new()`, `template.new(options)` and `template.new(safe)` (a `boolean`)
- Added `safe` implementation `require "resty.template.safe"`
- Added `echo` helper function to template (bungle#28)
- Added `template.load_file` and `template.load_string` functions
- Added `template.compile_file` and `template.compile_string` functions
- Added `template.parse_file` and `template.parse_string` functions
- Added `template.render_file` and `template.render_string` functions
- Added `template.precompile_file` and `template.precompile_string` functions
- Added `template.process`, `template.process_file` and `template.process_string` functions
- Added `template.root` and `template.location` properties
- Added `template.visit` function (bungle#36)

- When `plain` equals to `false` the file io issues are considered
  fatal, and assertions are thrown (bungle#32)

- Wrong template returned when using multiple server blocks (bungle#25)
- Add a pure lua configure method (bungle#23, #7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants