Sha256: 52a8582c8e7a702ca935d5d32130007041ef9ce022d0e320e485c2c40f2989c6

Contents?: true

Size: 733 Bytes

Versions: 2

Compression:

Stored size: 733 Bytes

Contents

module JsGenerator
  class ViewFile
    attr_reader :namespace, :model_name, :action_name, :syntax_builder

    def initialize(setup_js, syntax_builder)
      @namespace = setup_js.namespace
      @model_name = setup_js.model_name
      @action_name = setup_js.action_name
      @syntax_builder = syntax_builder
    end

    def append_script_tag
      File.open(file_path, 'a') { |f| f << script_tag }

      puts "📝 Appended <script> tag to #{file_path}"
    end

    private

    def file_path
      "app/views/#{namespace}/#{model_name.pluralize}/#{action_name}.html.erb"
    end

    def script_tag
      <<~TEXT
        <script>
          #{syntax_builder.action_namespace}();
        </script>
      TEXT
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
js_generator-0.1.4 lib/js_generator/view_file.rb
js_generator-0.1.3 lib/js_generator/view_file.rb