Class: Coolstrap::Generator::Generate::View

Inherits:
Object
  • Object
show all
Extended by:
Utils
Defined in:
lib/coolstrap-generator/generate/view.rb

Class Method Summary collapse

Methods included from Utils

base_location, create_directories, create_new_file, create_with_template, error, get_app_name, log, remove_directories, remove_files, templates, touch, underscore

Class Method Details

.create(name, context = {}) ⇒ Object



7
8
9
# File 'lib/coolstrap-generator/generate/view.rb', line 7

def create(name, context={})
  create_view_template(name, context)
end

.create_view_template(name, context) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/coolstrap-generator/generate/view.rb', line 12

def create_view_template(name, context)
  log "Creating #{name} view using a template."      
  view_directory = "source/views"
  context.merge!(:name => name)
  #log "#{context.inspect}"
  case context[:cs_type]
  when  'list'
    log("HINT: to use lists call them with href '##{name}' & data-target = 'section', and add the partial in index.html.haml ")
    template  = templates("app/components/listview/_simplelist.html.haml.erb")
  when  'complexlist'
    log("HINT: to use lists call them with href '##{name}' & data-target = 'section', and add the partial in index.html.haml ")
    template  = templates("app/components/listview/_complexlistavatar.html.haml.erb")
  when  'tabbar'
    view_directory = "source/views/tabbars"
    log("HINT: put partial in some header or footer element' ")
    template  = templates("app/components/tabbar.html.haml.erb")
  when  'toolbar'
    view_directory = "source/views/toolbars"
    log("HINT: put partial in some header or footer element' ")
    template  = templates("app/components/toolbar.html.haml.erb")
  when  'dialog'
    view_directory = "source/views/dialogs"
    log("HINT: put partial in index.html.haml, see comments' ")
    template  = templates("app/components/dialog.html.haml.erb")
  else
    log("HINT: to use lists call them with href '##{name}' & data-target = 'section', and add the partial in index.html.haml ")
    template  = templates("app/components/listview/_complexlistavatar.html.haml.erb")
  end
  
  payload   = Pathname.new("#{view_directory}/#{(context[:domain] || '').downcase}")
  contents  = Erubis::Eruby.new(File.read(template)).result(context) if template
  
  create_directories(payload)         unless File.directory?(payload)
  create_directories("spec/views")    unless File.directory?("spec/views")
  
  filename = payload.join("_#{name.downcase}.haml")
  File.open(location.join(filename), 'w') { |f| f.write(contents) }

  #create_new_file("spec/views/#{name}_spec.coffee", templates("specs/app_spec.coffee"))
  #create_new_file("app/#{underscore(app_name)}/stylesheets/_#{(context[:domain] || '').downcase}.sass", templates("app/stylesheets/sample.sass"))
  #append_to_router(context[:domain].capitalize, 'views')
end