curly-templates 2.6.2 → 2.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/README.md +7 -0
- data/lib/curly/version.rb +1 -1
- data/lib/generators/curly.rb +17 -0
- data/lib/generators/curly/install/install_generator.rb +21 -0
- data/lib/generators/curly/install/templates/layout.html.curly.erb +14 -0
- data/lib/generators/curly/install/templates/layout_presenter.rb.erb +25 -0
- data/lib/generators/curly/scaffold/scaffold_generator.rb +43 -0
- data/lib/generators/curly/scaffold/templates/_form.html.curly.erb +30 -0
- data/lib/generators/curly/scaffold/templates/edit.html.curly.erb +5 -0
- data/lib/generators/curly/scaffold/templates/edit_presenter.rb.erb +24 -0
- data/lib/generators/curly/scaffold/templates/form_presenter.rb.erb +66 -0
- data/lib/generators/curly/scaffold/templates/index.html.curly.erb +31 -0
- data/lib/generators/curly/scaffold/templates/index_presenter.rb.erb +46 -0
- data/lib/generators/curly/scaffold/templates/new.html.curly.erb +5 -0
- data/lib/generators/curly/scaffold/templates/new_presenter.rb.erb +20 -0
- data/lib/generators/curly/scaffold/templates/show.html.curly.erb +12 -0
- data/lib/generators/curly/scaffold/templates/show_presenter.rb.erb +46 -0
- metadata +18 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 02f8a17dc3592cc9292a69436aa2f807b8f6a6fa
|
4
|
+
data.tar.gz: 138af0504cf764736976934eaa4d3d7b33786d70
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 61567465adf49ea5b16e0cfe00414dda312019f723d83fba402ce07243a98c2f22f2345057bfcacb4c86180072cfa88be00f90ae70fca3987698c20d0d5c816e
|
7
|
+
data.tar.gz: 797cbdf8ebbea0e4842f27838f561e7e79f2121efcffc6494bdce2c72c6045ef994e21116d6d565d8b5d48090fd7f4580d0c2bdfe418e0fa3d1059c5b5b10a15
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
### Unreleased
|
2
2
|
|
3
|
+
### Curly 2.6.3 (March 24, 2017)
|
4
|
+
|
5
|
+
* Added generator for Rails' built in scaffold command.
|
6
|
+
* Added `curly:install` generator for creating layout files.
|
7
|
+
|
8
|
+
*Jack M*
|
9
|
+
|
3
10
|
### Curly 2.6.2 (December 22, 2016)
|
4
11
|
|
5
12
|
* Change `DependencyTracker.call` to returns array, for compatibility with
|
data/README.md
CHANGED
@@ -36,6 +36,13 @@ using Bundler to manage your dependencies, add this to your Gemfile
|
|
36
36
|
gem 'curly-templates'
|
37
37
|
```
|
38
38
|
|
39
|
+
Curly can also install an application layout file, replacing the .erb file commonly
|
40
|
+
created by Rails. If you wish to use this, run the `curly:install` generator.
|
41
|
+
|
42
|
+
```sh
|
43
|
+
$ rails generate curly:install
|
44
|
+
```
|
45
|
+
|
39
46
|
|
40
47
|
How to use Curly
|
41
48
|
----------------
|
data/lib/curly/version.rb
CHANGED
@@ -0,0 +1,21 @@
|
|
1
|
+
require "rails/generators/resource_helpers"
|
2
|
+
|
3
|
+
module Curly # :nodoc:
|
4
|
+
module Generators # :nodoc:
|
5
|
+
class InstallGenerator < Rails::Generators::Base # :nodoc:
|
6
|
+
|
7
|
+
source_root File.expand_path("../templates", __FILE__)
|
8
|
+
|
9
|
+
attr_reader :app_name
|
10
|
+
|
11
|
+
def generate_layout
|
12
|
+
app = ::Rails.application
|
13
|
+
@app_name = app.class.to_s.split("::").first
|
14
|
+
remove_file 'app/views/layouts/application.html.erb'
|
15
|
+
template "layout.html.curly.erb", "app/views/layouts/application.html.curly"
|
16
|
+
template "layout_presenter.rb.erb", "app/presenters/layouts/application_presenter.rb"
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
class Layouts::ApplicationPresenter < Curly::Presenter
|
2
|
+
# If you need to assign variables to the presenter, you can use the
|
3
|
+
# `presents` method.
|
4
|
+
#
|
5
|
+
# presents :foo, :bar
|
6
|
+
#
|
7
|
+
# Any public method defined in a presenter class will be available
|
8
|
+
# to the Curly template as a variable. Consider making these methods
|
9
|
+
# idempotent.
|
10
|
+
exposes_helper :csrf_meta_tags
|
11
|
+
|
12
|
+
def yield
|
13
|
+
yield
|
14
|
+
end
|
15
|
+
|
16
|
+
def stylesheet_links
|
17
|
+
stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'
|
18
|
+
end
|
19
|
+
|
20
|
+
def javascript_links
|
21
|
+
javascript_include_tag 'application', 'data-turbolinks-track': 'reload'
|
22
|
+
end
|
23
|
+
|
24
|
+
|
25
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
require "rails/generators/resource_helpers"
|
2
|
+
require "generators/curly"
|
3
|
+
|
4
|
+
module Curly # :nodoc:
|
5
|
+
module Generators # :nodoc:
|
6
|
+
class ScaffoldGenerator < Base # :nodoc:
|
7
|
+
include Rails::Generators::ResourceHelpers
|
8
|
+
|
9
|
+
source_root File.expand_path("../templates", __FILE__)
|
10
|
+
|
11
|
+
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
12
|
+
|
13
|
+
def create_root_folder
|
14
|
+
empty_directory File.join("app/views", controller_file_path)
|
15
|
+
empty_directory File.join("app/presenters", controller_file_path)
|
16
|
+
end
|
17
|
+
|
18
|
+
def copy_view_files
|
19
|
+
available_views.each do |view|
|
20
|
+
# Useful in the presenters.
|
21
|
+
@view_name = presenter_view(view)
|
22
|
+
# Example: posts/index.html.curly
|
23
|
+
view_file = "#{view}.#{format}.curly"
|
24
|
+
template "#{view_file}.erb", File.join("app/views", controller_file_path, view_file)
|
25
|
+
# Example: posts/index_presenter.rb
|
26
|
+
presenter_file = "#{@view_name}_presenter.rb"
|
27
|
+
template "#{presenter_file}.erb", File.join("app/presenters", controller_file_path, presenter_file)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
# Hack for _form view.
|
34
|
+
def presenter_view(view)
|
35
|
+
view.gsub(/^_/, '')
|
36
|
+
end
|
37
|
+
|
38
|
+
def available_views
|
39
|
+
%w(index show edit _form new)
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
{{@<%= singular_table_name %>_form}}
|
2
|
+
{{#<%= singular_table_name %>_errors:any?}}
|
3
|
+
<div id="error_explanation">
|
4
|
+
<h2>{{header}}</h2>
|
5
|
+
<ul>
|
6
|
+
{{*error_messages}}
|
7
|
+
<li>{{message}}</li>
|
8
|
+
{{/error_messages}}
|
9
|
+
</ul>
|
10
|
+
</div>
|
11
|
+
{{/<%= singular_table_name %>_errors:any?}}
|
12
|
+
<% attributes.each do |attribute| -%>
|
13
|
+
<div class="field">
|
14
|
+
<% if attribute.password_digest? -%>
|
15
|
+
{{label.password}}
|
16
|
+
{{field field_type="password_field" field_name="password"}}
|
17
|
+
</div>
|
18
|
+
|
19
|
+
<div class="field">
|
20
|
+
{{label field_name="password_confirmation"}}
|
21
|
+
{{field field_type="password_field" field_name="password_confirmation"}}
|
22
|
+
<% else -%>
|
23
|
+
{{label.<%= attribute.column_name %>}}
|
24
|
+
{{field field_type="<%= attribute.field_type %>" field_name="<%= attribute.column_name %>"}}
|
25
|
+
<% end -%>
|
26
|
+
</div>
|
27
|
+
<% end -%>
|
28
|
+
|
29
|
+
{{submit}}
|
30
|
+
{{/<%= singular_table_name %>_form}}
|
@@ -0,0 +1,24 @@
|
|
1
|
+
class <%= plural_table_name.capitalize %>::<%= @view_name.capitalize %>Presenter < Curly::Presenter
|
2
|
+
# If you need to assign variables to the presenter, you can use the
|
3
|
+
# `presents` method.
|
4
|
+
#
|
5
|
+
# presents :foo, :bar
|
6
|
+
#
|
7
|
+
# Any public method defined in a presenter class will be available
|
8
|
+
# to the Curly template as a variable. Consider making these methods
|
9
|
+
# idempotent.
|
10
|
+
presents :<%= singular_table_name %>
|
11
|
+
|
12
|
+
def <%= singular_table_name %>
|
13
|
+
@<%= singular_table_name %>
|
14
|
+
end
|
15
|
+
|
16
|
+
def <%= singular_table_name %>_form
|
17
|
+
render 'form', <%= singular_table_name %>: @<%= singular_table_name %>
|
18
|
+
end
|
19
|
+
|
20
|
+
def <%= index_helper %>_link
|
21
|
+
link_to 'Back', <%= index_helper %>_path
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
class <%= plural_table_name.capitalize %>::<%= @view_name.capitalize %>Presenter < Curly::Presenter
|
2
|
+
# If you need to assign variables to the presenter, you can use the
|
3
|
+
# `presents` method.
|
4
|
+
#
|
5
|
+
# presents :foo, :bar
|
6
|
+
#
|
7
|
+
# Any public method defined in a presenter class will be available
|
8
|
+
# to the Curly template as a variable. Consider making these methods
|
9
|
+
# idempotent.
|
10
|
+
presents :<%= singular_table_name %>
|
11
|
+
|
12
|
+
def post_errors
|
13
|
+
@post.errors
|
14
|
+
end
|
15
|
+
|
16
|
+
def <%= singular_table_name %>
|
17
|
+
@<%= singular_table_name %>
|
18
|
+
end
|
19
|
+
|
20
|
+
def <%= singular_table_name %>_form(&block)
|
21
|
+
form_for(@<%= singular_table_name %>, &block)
|
22
|
+
end
|
23
|
+
|
24
|
+
class <%= singular_table_name.capitalize %>FormPresenter < Curly::Presenter
|
25
|
+
presents :<%= singular_table_name %>_form, :<%= singular_table_name %>
|
26
|
+
|
27
|
+
def <%= singular_table_name %>_errors(&block)
|
28
|
+
block.call(@post.errors)
|
29
|
+
end
|
30
|
+
|
31
|
+
def label(field_name)
|
32
|
+
@<%= singular_table_name %>_form.label field_name.to_sym
|
33
|
+
end
|
34
|
+
|
35
|
+
def field(field_type: nil, field_name: nil)
|
36
|
+
@<%= singular_table_name %>_form.send field_type.to_sym, field_name.to_sym
|
37
|
+
end
|
38
|
+
|
39
|
+
def submit
|
40
|
+
@<%= singular_table_name %>_form.submit
|
41
|
+
end
|
42
|
+
|
43
|
+
class <%= singular_table_name.capitalize %>ErrorsPresenter < Curly::Presenter
|
44
|
+
presents :<%= singular_table_name %>_errors
|
45
|
+
|
46
|
+
def any?
|
47
|
+
@<%= singular_table_name %>_errors.any?
|
48
|
+
end
|
49
|
+
|
50
|
+
def header
|
51
|
+
"#{pluralize(@<%= singular_table_name %>_errors.count, "error")} prohibited this <%= singular_table_name %> from being saved:"
|
52
|
+
end
|
53
|
+
|
54
|
+
def error_messages(&block)
|
55
|
+
@<%= singular_table_name %>_errors.full_messages
|
56
|
+
end
|
57
|
+
|
58
|
+
class ErrorMessagePresenter < Curly::Presenter
|
59
|
+
presents :error_message
|
60
|
+
def message
|
61
|
+
@error_message
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
<p id="notice">{{notice_text}}</p>
|
2
|
+
|
3
|
+
<h1><%= plural_table_name.titleize %></h1>
|
4
|
+
|
5
|
+
<table>
|
6
|
+
<thead>
|
7
|
+
<tr>
|
8
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
9
|
+
<th><%= attribute.human_name %></th>
|
10
|
+
<% end -%>
|
11
|
+
<th colspan="3"></th>
|
12
|
+
</tr>
|
13
|
+
</thead>
|
14
|
+
|
15
|
+
<tbody>
|
16
|
+
{{*<%= plural_table_name %>}}
|
17
|
+
<tr>
|
18
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
19
|
+
<td>{{<%= attribute.name %>}}</td>
|
20
|
+
<% end -%>
|
21
|
+
<td>{{show_link}}</td>
|
22
|
+
<td>{{edit_link}}</td>
|
23
|
+
<td>{{destroy_link}}</td>
|
24
|
+
</tr>
|
25
|
+
{{/<%= plural_table_name %>}}
|
26
|
+
</tbody>
|
27
|
+
</table>
|
28
|
+
|
29
|
+
<br>
|
30
|
+
|
31
|
+
{{create_link}}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class <%= plural_table_name.capitalize %>::<%= @view_name.capitalize %>Presenter < Curly::Presenter
|
2
|
+
# If you need to assign variables to the presenter, you can use the
|
3
|
+
# `presents` method.
|
4
|
+
#
|
5
|
+
# presents :foo, :bar
|
6
|
+
#
|
7
|
+
# Any public method defined in a presenter class will be available
|
8
|
+
# to the Curly template as a variable. Consider making these methods
|
9
|
+
# idempotent.
|
10
|
+
presents :<%= plural_table_name %>
|
11
|
+
|
12
|
+
def <%= plural_table_name %>
|
13
|
+
@<%= plural_table_name %>
|
14
|
+
end
|
15
|
+
|
16
|
+
def notice_text
|
17
|
+
notice
|
18
|
+
end
|
19
|
+
|
20
|
+
def create_link
|
21
|
+
link_to 'New <%= singular_table_name.titleize %>', new_<%= singular_table_name %>_path
|
22
|
+
end
|
23
|
+
|
24
|
+
class <%= singular_table_name.capitalize %>Presenter < Curly::Presenter
|
25
|
+
presents :<%= singular_table_name %>
|
26
|
+
|
27
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
28
|
+
def <%= attribute.name %>
|
29
|
+
@<%= singular_table_name %>.<%= attribute.name %>
|
30
|
+
end
|
31
|
+
<% end -%>
|
32
|
+
|
33
|
+
def show_link
|
34
|
+
link_to 'Show', @<%= singular_table_name %>
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit_link
|
38
|
+
link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy_link
|
42
|
+
link_to 'Destroy', @<%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
class <%= plural_table_name.capitalize %>::<%= @view_name.capitalize %>Presenter < Curly::Presenter
|
2
|
+
# If you need to assign variables to the presenter, you can use the
|
3
|
+
# `presents` method.
|
4
|
+
#
|
5
|
+
# presents :foo, :bar
|
6
|
+
#
|
7
|
+
# Any public method defined in a presenter class will be available
|
8
|
+
# to the Curly template as a variable. Consider making these methods
|
9
|
+
# idempotent.
|
10
|
+
presents :<%= singular_table_name %>
|
11
|
+
|
12
|
+
def <%= singular_table_name %>_form
|
13
|
+
render 'form', <%= singular_table_name %>: @<%= singular_table_name %>
|
14
|
+
end
|
15
|
+
|
16
|
+
def <%= index_helper %>_link
|
17
|
+
link_to 'Back', <%= index_helper %>_path
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
<p id="notice">{{notice_text}}</p>
|
2
|
+
|
3
|
+
{{*<%= singular_table_name %>}}
|
4
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
5
|
+
<p>
|
6
|
+
<strong><%= attribute.human_name %>:</strong>
|
7
|
+
{{<%= attribute.name %>}}
|
8
|
+
</p>
|
9
|
+
<% end -%>
|
10
|
+
{{edit_link}}
|
11
|
+
{{/<%= singular_table_name %>}}
|
12
|
+
{{<%= index_helper %>_link}}
|
@@ -0,0 +1,46 @@
|
|
1
|
+
class <%= plural_table_name.capitalize %>::<%= @view_name.capitalize %>Presenter < Curly::Presenter
|
2
|
+
# If you need to assign variables to the presenter, you can use the
|
3
|
+
# `presents` method.
|
4
|
+
#
|
5
|
+
# presents :foo, :bar
|
6
|
+
#
|
7
|
+
# Any public method defined in a presenter class will be available
|
8
|
+
# to the Curly template as a variable. Consider making these methods
|
9
|
+
# idempotent.
|
10
|
+
presents :<%= singular_table_name %>
|
11
|
+
|
12
|
+
def <%= singular_table_name %>
|
13
|
+
@<%= singular_table_name %>
|
14
|
+
end
|
15
|
+
|
16
|
+
def notice_text
|
17
|
+
notice
|
18
|
+
end
|
19
|
+
|
20
|
+
def <%= index_helper %>_link
|
21
|
+
link_to 'Back', <%= index_helper %>_path
|
22
|
+
end
|
23
|
+
|
24
|
+
class <%= singular_table_name.capitalize %>Presenter < Curly::Presenter
|
25
|
+
presents :<%= singular_table_name %>
|
26
|
+
|
27
|
+
<% attributes.reject(&:password_digest?).each do |attribute| -%>
|
28
|
+
def <%= attribute.name %>
|
29
|
+
@<%= singular_table_name %>.<%= attribute.name %>
|
30
|
+
end
|
31
|
+
<% end -%>
|
32
|
+
|
33
|
+
def show_link
|
34
|
+
link_to 'Show', @<%= singular_table_name %>
|
35
|
+
end
|
36
|
+
|
37
|
+
def edit_link
|
38
|
+
link_to 'Edit', edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
|
39
|
+
end
|
40
|
+
|
41
|
+
def destroy_link
|
42
|
+
link_to 'Destroy', @<%= singular_table_name %>, method: :delete, data: { confirm: 'Are you sure?' }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: curly-templates
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.6.
|
4
|
+
version: 2.6.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Daniel Schierbeck
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2017-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: actionpack
|
@@ -144,9 +144,24 @@ files:
|
|
144
144
|
- lib/curly/syntax_error.rb
|
145
145
|
- lib/curly/template_handler.rb
|
146
146
|
- lib/curly/version.rb
|
147
|
+
- lib/generators/curly.rb
|
147
148
|
- lib/generators/curly/controller/controller_generator.rb
|
148
149
|
- lib/generators/curly/controller/templates/presenter.rb.erb
|
149
150
|
- lib/generators/curly/controller/templates/view.html.curly.erb
|
151
|
+
- lib/generators/curly/install/install_generator.rb
|
152
|
+
- lib/generators/curly/install/templates/layout.html.curly.erb
|
153
|
+
- lib/generators/curly/install/templates/layout_presenter.rb.erb
|
154
|
+
- lib/generators/curly/scaffold/scaffold_generator.rb
|
155
|
+
- lib/generators/curly/scaffold/templates/_form.html.curly.erb
|
156
|
+
- lib/generators/curly/scaffold/templates/edit.html.curly.erb
|
157
|
+
- lib/generators/curly/scaffold/templates/edit_presenter.rb.erb
|
158
|
+
- lib/generators/curly/scaffold/templates/form_presenter.rb.erb
|
159
|
+
- lib/generators/curly/scaffold/templates/index.html.curly.erb
|
160
|
+
- lib/generators/curly/scaffold/templates/index_presenter.rb.erb
|
161
|
+
- lib/generators/curly/scaffold/templates/new.html.curly.erb
|
162
|
+
- lib/generators/curly/scaffold/templates/new_presenter.rb.erb
|
163
|
+
- lib/generators/curly/scaffold/templates/show.html.curly.erb
|
164
|
+
- lib/generators/curly/scaffold/templates/show_presenter.rb.erb
|
150
165
|
- lib/rails/projections.json
|
151
166
|
homepage: https://github.com/zendesk/curly
|
152
167
|
licenses:
|
@@ -169,7 +184,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
169
184
|
version: '0'
|
170
185
|
requirements: []
|
171
186
|
rubyforge_project:
|
172
|
-
rubygems_version: 2.5.
|
187
|
+
rubygems_version: 2.4.5.1
|
173
188
|
signing_key:
|
174
189
|
specification_version: 2
|
175
190
|
summary: Free your views!
|