props_template 1.0.1 → 1.0.2

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7b3bde6ce57e684648932f2fc307d1ad885679ee21428b0c7ee66cc31c13ee67
4
- data.tar.gz: aa90aea1e4c0950702619b26183647b74f18f5bfd0fb18808ae8c8d347803ed4
3
+ metadata.gz: d701cbf0bc05a74ec52fcab3e939b795bdb99eefc436b1bb5029d24deff16aac
4
+ data.tar.gz: da5e8ab92010fcf43d147cd677527024904fa57a0914f17737cccdf81e014bc5
5
5
  SHA512:
6
- metadata.gz: aab15761d3b7edb82d1f2d637a8ca0dcd3ab2241caa74ab75d4e6226c82a5b513308194c670f7ce1d3ab3c6b80d8fd8111332f9bb4705acd3b70ac05564132bc
7
- data.tar.gz: d66cc1d55181b2fb948d393fcc4bac96fb91546ca999d1e3c6634b58309f47cf4b036ed1f7ad9671eb9e63e104e48e5c850907a1b6710d8790481f45b4f470d5
6
+ metadata.gz: 4a0e09a2b3845cfb26a682f0fa4cde60bcfb156d671e96c8a0cba443bfcd65b30017202bd174e649055bc5b7971317b5b8bc9a60185721d4fc94adb48744a441
7
+ data.tar.gz: f4ad6bdd2ac66c9504ed79f0bc28b1a2a486432be47b31700b31783fa93d7c8d4826eeea33d4de1d00fc281b21345db5cc563e2e66d22282792d98a8fa9a03ec
@@ -0,0 +1,11 @@
1
+ json.<%= js_plural_table_name %> do
2
+ json.array! @<%= plural_table_name %> do |<%= singular_table_name %>|
3
+ <%- attributes_list_with_timestamps.each do |attr| -%>
4
+ json.<%=attr.to_s.camelize(:lower)%> <%= singular_table_name %>.<%=attr%>
5
+ <%- end -%>
6
+ json.edit<%=js_singular_table_name(:upper)%>Path edit_<%=singular_table_name%>_path(<%=singular_table_name%>)
7
+ json.<%=js_singular_table_name%>Path <%=singular_table_name%>_path(<%=singular_table_name%>)
8
+ end
9
+ end
10
+
11
+ json.new<%= js_singular_table_name(:upper) %>Path new_<%= singular_table_name %>_path
@@ -0,0 +1,6 @@
1
+ <%- attributes_list_with_timestamps.each do |attr|-%>
2
+ json.<%=attr.to_s.camelize(:lower)%> @<%= singular_table_name %>.<%=attr%>
3
+ <%- end -%>
4
+
5
+ json.<%= js_plural_table_name %>Path <%= plural_table_name %>_path
6
+ json.edit<%= js_singular_table_name(:upper) %>Path edit_<%= singular_table_name %>_path(@<%= singular_table_name %>)
@@ -0,0 +1,9 @@
1
+ Description:
2
+ Generates PropsTemplate view files (.json.props) for a given resource.
3
+
4
+ Example:
5
+ rails generate props:views Post title:string body:text
6
+
7
+ This will create:
8
+ app/views/posts/index.json.props
9
+ app/views/posts/show.json.props
@@ -0,0 +1,64 @@
1
+ require "rails/generators/named_base"
2
+ require "rails/generators/resource_helpers"
3
+
4
+ module Props
5
+ module Generators
6
+ class ViewsGenerator < Rails::Generators::NamedBase
7
+ include Rails::Generators::ResourceHelpers
8
+
9
+ source_root File.expand_path("../templates", __dir__)
10
+
11
+ argument :attributes, type: :array, default: [], banner: "field:type field:type"
12
+
13
+ def create_root_folder
14
+ path = File.join("app/views", controller_file_path)
15
+ empty_directory path unless File.directory?(path)
16
+ end
17
+
18
+ def copy_prop_files
19
+ available_views.each do |view|
20
+ @action_name = view
21
+ filename = filename_with_extensions(view)
22
+ template filename, File.join("app/views", controller_file_path, filename)
23
+ end
24
+ end
25
+
26
+ protected
27
+
28
+ def js_singular_table_name(casing = :lower)
29
+ singular_table_name.camelize(casing)
30
+ end
31
+
32
+ def js_plural_table_name(casing = :lower)
33
+ plural_table_name.camelize(casing)
34
+ end
35
+
36
+ def available_views
37
+ %w[index show]
38
+ end
39
+
40
+ attr_reader :action_name
41
+
42
+ def attributes_names
43
+ [:id] + super
44
+ end
45
+
46
+ def filename_with_extensions(name)
47
+ [name, :json, :props].join(".")
48
+ end
49
+
50
+
51
+ def attributes_list_with_timestamps
52
+ attributes_list(attributes_names + %w[created_at updated_at])
53
+ end
54
+
55
+ def attributes_list(attributes = attributes_names)
56
+ if self.attributes.any? { |attr| attr.name == "password" && attr.type == :digest }
57
+ attributes = attributes.reject { |name| %w[password password_confirmation].include? name }
58
+ end
59
+
60
+ attributes
61
+ end
62
+ end
63
+ end
64
+ end
@@ -49,9 +49,15 @@ module Props
49
49
  partial = partial_opts[:partial]
50
50
  template_keys = retrieve_template_keys(partial_opts)
51
51
  details = extract_details(partial_opts)
52
+ lookup_context = @context.lookup_context
52
53
 
53
- prefixes = partial.include?("/") ? [] : @context.lookup_context.prefixes
54
- @context.lookup_context.find_template(partial, prefixes, true, template_keys, details)
54
+ prefixes = partial.include?("/") ? [] : lookup_context.prefixes
55
+
56
+ if lookup_context.respond_to?(:find!)
57
+ lookup_context.find!(partial, prefixes, true, template_keys, details)
58
+ else
59
+ lookup_context.find_template(partial, prefixes, true, template_keys, details)
60
+ end
55
61
  end
56
62
 
57
63
  def retrieve_template_keys(options)
@@ -1,3 +1,3 @@
1
1
  module Props
2
- VERSION = "1.0.1".freeze
2
+ VERSION = "1.0.2".freeze
3
3
  end
@@ -59,7 +59,11 @@ module Props
59
59
  @builder = prev_builder
60
60
  @fragment_path = fragment_path
61
61
 
62
- if found_block
62
+ # An inline options object, e.g. `json.foo(with.partial("foo"))`, has
63
+ # no block; its content comes from the options instead.
64
+ found_inline_options = found_options.is_a?(Props::Options)
65
+
66
+ if found_block || found_inline_options
63
67
  @builder.item_context = found_item
64
68
  set!(key, found_options, &found_block)
65
69
  end
@@ -72,8 +76,11 @@ module Props
72
76
  @context.render options
73
77
  end
74
78
 
79
+ # Relative to the fragment the dig ended in, so the client can graft into
80
+ # it; the full path when no fragment was crossed.
75
81
  def found_path!
76
- @found_path[@fragment_path.size..].join(".")
82
+ fragment_path = @fragment_path || []
83
+ @found_path[fragment_path.size..].join(".")
77
84
  end
78
85
 
79
86
  def fragment_context!
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: props_template
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Johny Ho
@@ -72,6 +72,10 @@ extensions: []
72
72
  extra_rdoc_files: []
73
73
  files:
74
74
  - README.md
75
+ - lib/generators/props/templates/index.json.props
76
+ - lib/generators/props/templates/show.json.props
77
+ - lib/generators/props/views/USAGE
78
+ - lib/generators/props/views/views_generator.rb
75
79
  - lib/props_template.rb
76
80
  - lib/props_template/base.rb
77
81
  - lib/props_template/base_with_extensions.rb
@@ -108,7 +112,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
112
  - !ruby/object:Gem::Version
109
113
  version: '0'
110
114
  requirements: []
111
- rubygems_version: 3.6.9
115
+ rubygems_version: 4.0.16
112
116
  specification_version: 4
113
117
  summary: A fast JSON builder
114
118
  test_files: []