Top Level Namespace

Defined Under Namespace

Modules: Jt

Constant Summary collapse

@@page_context =

page_context

{}

Instance Method Summary collapse

Instance Method Details

#base_js(file) ⇒ Object

js



2
3
4
5
# File 'lib/jt-partial/js.rb', line 2

def base_js(file)
  is_base_file = file.include?( "application.js" ) || file.include?("routes.js")
  is_base_file
end

#container(template_path, args, &block) ⇒ Object



8
9
10
11
12
# File 'lib/jt-partial/haml_toolkit.rb', line 8

def container template_path, args, &block
  Haml::Engine.new(File.read(template_path)).render Object.new, args do
    capture_haml( &block )
  end
end

#generate(template_name) ⇒ Object



11
12
13
14
# File 'lib/jt-partial/partial.rb', line 11

def generate(template_name)
  template_path = "_#{template_name}.haml"
  render_and_output_to_file template_path, template_name
end

#haml_render(template_path, args = {}) ⇒ Object

haml toolkit



3
4
5
# File 'lib/jt-partial/haml_toolkit.rb', line 3

def haml_render(template_path, args = {})
  Haml::Engine.new(File.read(template_path)).render Object.new, args
end

#html(partial) ⇒ Object



7
8
9
# File 'lib/jt-partial/partial.rb', line 7

def html(partial)
  File.read(partial)
end

#include_jsObject



7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/jt-partial/js.rb', line 7

def include_js
  template_path = File.expand_path('../', __FILE__)
  template = ""
  js_files = File.join("js","**", "*.js")
  Dir.glob js_files do |file|
    if ! base_js file
      template += haml_render "#{template_path}/_js_script_tag.haml",  {:js_file_path => file}
    end
  end
  template += haml_render "#{template_path}/_js_script_tag.haml",  {:js_file_path => "js/application.js"}
  template += haml_render "#{template_path}/_js_script_tag.haml",  {:js_file_path => "js/routes.js"}
  template
end

#load_page(page_name) ⇒ Object



4
5
6
7
8
# File 'lib/jt-partial/page_context.rb', line 4

def load_page page_name
  @@page_context[:name] = page_name
  page_path = "pages/_#{page_name}.haml"
  haml_render page_path
end

#partial(partial) ⇒ Object

partial



2
3
4
5
# File 'lib/jt-partial/partial.rb', line 2

def partial(partial)
  partial_path = "_#{partial}.haml"
  haml_render(partial_path)
end

#render_and_output_to_file(template_path, output_path) ⇒ Object



16
17
18
19
20
# File 'lib/jt-partial/partial.rb', line 16

def render_and_output_to_file(template_path, output_path)
  output = haml_render(template_path)
  html_page = File.new("#{output_path}.html", "w")
  html_page.write(output)
end