curly-templates 2.6.1 → 3.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +5 -5
- data/.github/workflows/ci.yml +27 -0
- data/.travis.yml +1 -1
- data/CHANGELOG.md +31 -1
- data/Gemfile +1 -14
- data/README.md +9 -3
- data/curly-templates.gemspec +3 -3
- data/gemfiles/common.rb +13 -0
- data/gemfiles/rails4.2.gemfile +4 -0
- data/gemfiles/rails4.2.gemfile.lock +161 -0
- data/gemfiles/rails5.1.gemfile +4 -0
- data/gemfiles/rails5.1.gemfile.lock +169 -0
- data/gemfiles/rails5.2.gemfile +4 -0
- data/gemfiles/rails5.2.gemfile.lock +177 -0
- data/gemfiles/rails6.0.gemfile +4 -0
- data/gemfiles/rails6.0.gemfile.lock +199 -0
- data/gemfiles/rails6.1.gemfile +4 -0
- data/gemfiles/rails6.1.gemfile.lock +202 -0
- data/lib/curly/dependency_tracker.rb +1 -1
- data/lib/curly/template_handler.rb +20 -8
- 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 +44 -19
- data/circle.yml +0 -9
@@ -13,9 +13,17 @@ class Curly::TemplateHandler
|
|
13
13
|
# template - The ActionView::Template template that should be compiled.
|
14
14
|
#
|
15
15
|
# Returns a String containing the Ruby code representing the template.
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
if ActionView::VERSION::MAJOR < 6
|
17
|
+
def call(template)
|
18
|
+
instrument(template) do
|
19
|
+
compile_for_actionview5(template)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
else
|
23
|
+
def call(template, source)
|
24
|
+
instrument(template) do
|
25
|
+
compile(template, source)
|
26
|
+
end
|
19
27
|
end
|
20
28
|
end
|
21
29
|
|
@@ -40,16 +48,20 @@ class Curly::TemplateHandler
|
|
40
48
|
|
41
49
|
private
|
42
50
|
|
43
|
-
def
|
44
|
-
|
45
|
-
|
51
|
+
def compile_for_actionview5(template)
|
52
|
+
compile(template, template.source)
|
53
|
+
end
|
54
|
+
|
55
|
+
def compile(template, source)
|
56
|
+
# Template source is empty, so there's no need to initialize a presenter.
|
57
|
+
return %("") if source.empty?
|
46
58
|
|
47
59
|
path = template.virtual_path
|
48
60
|
presenter_class = Curly::Presenter.presenter_for_path(path)
|
49
61
|
|
50
62
|
raise Curly::PresenterNotFound.new(path) if presenter_class.nil?
|
51
63
|
|
52
|
-
|
64
|
+
compiled_source = Curly.compile(source, presenter_class)
|
53
65
|
|
54
66
|
<<-RUBY
|
55
67
|
if local_assigns.empty?
|
@@ -64,7 +76,7 @@ class Curly::TemplateHandler
|
|
64
76
|
@output_buffer = output_buffer || ActiveSupport::SafeBuffer.new
|
65
77
|
|
66
78
|
Curly::TemplateHandler.cache_if_key_is_not_nil(self, presenter) do
|
67
|
-
result = #{
|
79
|
+
result = #{compiled_source}
|
68
80
|
safe_concat(result)
|
69
81
|
end
|
70
82
|
|
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 <%= singular_table_name %>_errors
|
13
|
+
@<%= singular_table_name %>.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(@<%= singular_table_name %>.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}}
|