Class: MegaBar::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- MegaBar::Page
- Defined in:
- app/models/mega_bar/page.rb
Instance Attribute Summary collapse
-
#base_name ⇒ Object
Returns the value of attribute base_name.
-
#block_text ⇒ Object
Returns the value of attribute block_text.
-
#make_layout_and_block ⇒ Object
Returns the value of attribute make_layout_and_block.
-
#model_id ⇒ Object
Returns the value of attribute model_id.
-
#template_id ⇒ Object
Returns the value of attribute template_id.
Instance Method Summary collapse
Instance Attribute Details
#base_name ⇒ Object
Returns the value of attribute base_name.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def base_name @base_name end |
#block_text ⇒ Object
Returns the value of attribute block_text.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def block_text @block_text end |
#make_layout_and_block ⇒ Object
Returns the value of attribute make_layout_and_block.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def make_layout_and_block @make_layout_and_block end |
#model_id ⇒ Object
Returns the value of attribute model_id.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def model_id @model_id end |
#template_id ⇒ Object
Returns the value of attribute template_id.
5 6 7 |
# File 'app/models/mega_bar/page.rb', line 5 def template_id @template_id end |
Instance Method Details
#add_route ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
# File 'app/models/mega_bar/page.rb', line 20 def add_route return if ENV['RAILS_ENV'] == 'test' Rails.application.reload_routes! # this now just adds it to the spec_helper. gem_path = '' # line = ' ##### MEGABAR END' # text = File.read('spec/spec_helper.rb') # if self.model_id # mod = Model.find(self.model_id) # gem_path = Rails.root + '../megabar/' if File.directory?(Rails.root + '../megabar/') && mod.modyule == 'MegaBar' # route_text = ' resources :' + mod.classname.downcase.pluralize # route_text += ", path: '#{self.path}'" if '/' + mod.tablename != self.path # route_text += "\n #{line}" # else # route_text = "get '#{self.path}', to: 'flats#index'" # route_text += "\n #{line}" # end # new_contents = text.gsub( /(#{Regexp.escape(line)})/mi, route_text) # # To write changes to the file, use: # File.open(gem_path + 'spec/spec_helper.rb', "w") {|file| file.puts new_contents } # unless gem_path == '' && mod.modyule == 'MegaBar' # @@notices << "You will have to add the route yourself manually to the megabar route file: #{route_text}" if gem_path == '' && modyule == 'MegaBar' end |
#create_layout_for_page ⇒ Object
11 12 13 14 15 16 17 18 |
# File 'app/models/mega_bar/page.rb', line 11 def create_layout_for_page base_name = (self.base_name.nil? || self.base_name.empty?) ? self.name : self.base_name template_id = self.template_id.present? ? self.template_id : self.make_layout_and_block layout_hash = {page_id: self.id, name: base_name.humanize + ' Layout', base_name: base_name, make_block: true, model_id: self.model_id, template_id: template_id} layout_hash = layout_hash.merge({block_text: self.block_text}) if self.block_text # byebug _layout = Layout.create(layout_hash) if (!Layout.by_page(self.id).present? && template_id.present?) end |