Module: Vue::Helpers::Methods
- Defined in:
- lib/vue/helpers/methods.rb,
lib/vue/helpers/helper_refinements.rb,
lib/vue/helpers/helper_refinements.rb
Overview
Use MethodsBlock as regular Module methods if Ruby < 2.4.
Class Method Summary collapse
Instance Method Summary collapse
- #vue_app(root_name = nil, **options) ⇒ Object
-
#vue_component(name, root_name: nil, tag_name: nil, locals: {}, attributes: {}, **options, &block) ⇒ Object
Inserts Vue component-call block in html template.
- #vue_repository ⇒ Object (also: #vue_repo)
-
#vue_root(root_name = Vue::Helpers.root_name, locals: {}, **options, &block) ⇒ Object
Inserts Vue app-call block in html template.
Class Method Details
.included(other) ⇒ Object
20 21 22 23 24 25 26 27 28 29 |
# File 'lib/vue/helpers/methods.rb', line 20 def self.included(other) # If Rails if other.name[/Helper/] && Module.const_defined?(:ActionView) # TODO: This should be logger.debug. puts "#{other} including ActionView::Helpers::CaptureHelper" include ActionView::Helpers::CaptureHelper end other.send(:prepend, ControllerPrepend) end |
Instance Method Details
#vue_app(root_name = nil, **options) ⇒ Object
38 39 40 |
# File 'lib/vue/helpers/methods.rb', line 38 def vue_app(root_name=nil, **) vue_repository.root(root_name, **) end |
#vue_component(name, root_name: nil, tag_name: nil, locals: {}, attributes: {}, **options, &block) ⇒ Object
Inserts Vue component-call block in html template. Name & file_name refer to file-name.vue.<template_engine> SFC file. Example: products.vue.erb.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/vue/helpers/methods.rb', line 44 def vue_component(name, root_name:nil, tag_name:nil, locals:{}, attributes:{}, **, &block ) #puts "\nvue_component '#{name}' with local-vars '#{local_variables.inject({}){ |c, i| c[i.to_s] = eval(i.to_s); c }}'" # This should only pass args that are necessary to build the component object. # Tag-name and attributes are not relevant here. component = vue_app(root_name).component(name, locals:locals, **) # Renders the per-call html block. # Pass tag_name, attributes, locals, and block. component_output = component.render(tag_name, locals:locals, attributes:attributes, &block) # Concat the content if block given, otherwise just return the content. if block_given? #puts "Vue_component concating content for '#{name}'" #: #{component_output[0..32].gsub(/\n/, ' ')}" concat_content(component_output) else #puts "Vue_component returning content for '#{name}'" #: #{component_output[0..32].gsub(/\n/, ' ')}" return component_output end end |
#vue_repository ⇒ Object Also known as: vue_repo
31 32 33 34 35 |
# File 'lib/vue/helpers/methods.rb', line 31 def vue_repository @vue_repository ||= VueRepository.new(context=self) #puts "Getting vue_repository #{@vue_repository.class} with keys: #{@vue_repository.keys}" @vue_repository end |
#vue_root(root_name = Vue::Helpers.root_name, locals: {}, **options, &block) ⇒ Object
Inserts Vue app-call block in html template. Builds vue html and js for return to browser.
Returns (or concats if block given) rendered html and js.
78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 |
# File 'lib/vue/helpers/methods.rb', line 78 def vue_root(root_name = Vue::Helpers.root_name, locals: {}, **, &block ) #puts "\nvue_root '#{root_name}' with local-vars '#{local_variables.inject({}) { |c, i| c[i.to_s] = eval(i.to_s); c }}'" root_app = vue_app(root_name, locals:locals, **) root_output = root_app.render(locals:locals, &block) if block_given? concat_content(root_output) else root_output end end |