Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit 63789585124c5f3383c78553cb18edf1e21fc933 0 parents
@robert-hromej authored
2  .gitignore
@@ -0,0 +1,2 @@
+.idea
+tmp/*
1  .rvmrc
@@ -0,0 +1 @@
+rvm ruby-1.9.3@tk_haml
4 Gemfile
@@ -0,0 +1,4 @@
+source 'http://rubygems.org'
+
+gem 'haml'
+gem 'liquid'
12 Gemfile.lock
@@ -0,0 +1,12 @@
+GEM
+ remote: http://rubygems.org/
+ specs:
+ haml (3.1.4)
+ liquid (2.3.0)
+
+PLATFORMS
+ ruby
+
+DEPENDENCIES
+ haml
+ liquid
66 lib/haml/engine.rb
@@ -0,0 +1,66 @@
+module EngineMethods
+
+ def to_tk_module
+ #str = "module Layout\n"
+ #
+ #components = ['label1', 'label2', 'frame1']
+ #
+ #str << "\n"
+ #str << " def init_all_component\n"
+ #components.each do |component|
+ # str << " #{component}\n"
+ #end
+ #str << " end\n"
+ #
+ #
+ #str << "end\n"
+ #
+ #create_element @root.children[0].children[0]
+ #create_element @root.children[0].children[1]
+ #
+ #
+ #str
+
+ module_template = Liquid::Template.parse File.read('./lib/templates/application.liquid')
+
+ methods = []
+
+ components = []
+
+ @root.to_tk.each do |aaa|
+ components << aaa[0]
+ methods << aaa[1]
+ end
+
+ init_components_template = Liquid::Template.parse File.read('./lib/templates/init_components.liquid')
+ methods << init_components_template.render('components' => components.join("\n "))
+ module_template.render('methods' => methods)
+ end
+
+ def create_element node
+ id = node.value[:attributes]['id']
+
+ type = node.value[:name]
+ type = 'frame' if node.value[:name] == 'div'
+
+ parent = node.parent.value[:attributes]['id']
+
+ str = "\n"
+ str << " def #{id}\n"
+ str << " return @#{id} if @#{id}\n\n"
+ str << " @#{id} = #{type.capitalize}.new(#{parent})\n"
+ str << " end\n"
+
+ puts str
+ end
+
+ def render_tk_module
+ File.open('./app/application.rb', 'w') { |f| f.puts to_tk_module }
+ end
+end
+
+module Haml
+ class Engine
+ include EngineMethods
+ end
+end
103 lib/haml/parser.rb
@@ -0,0 +1,103 @@
+module ParseNodeMethods
+
+ def is_root?
+ parent.nil?
+ end
+
+ def id
+ is_root? ? 'root' : value[:attributes]['id']
+ end
+
+ def name
+ value[:name] = "frame" if value[:name] == 'div'
+ value[:name]
+ end
+
+ def label_id
+ is_root? ? 'application' : value[:attributes]['class']
+ end
+
+ def to_tk
+ return [] unless [:tag, :root].include? type
+
+ template = Liquid::Template.parse File.read('./lib/templates/getter.liquid')
+
+ if is_root?
+ getter = template.render('name' => id, 'type' => 'TkRoot')
+ else
+ getter = template.render('name' => id, 'type' => name.capitalize, 'parent' => parent.id)
+ end
+
+ result = [[id, getter]]
+
+ children.each do |child|
+ result += child.to_tk
+ end
+
+ result
+=begin
+ self.ruby_som = Frame.new(root)
+ self.btn1 = Button.new(ruby_som)
+ self.btn1.width = 243
+=end
+
+
+ #attr = {}
+ #
+ #attr['file_name'] = label_id
+ #attr['class_name'] = label_id.capitalize
+ #
+ #attr['attrs'] = children.find_all { |child| [:tag, :root].include? child.type }
+ #attr['attrs'] = attr['attrs'].map { |a| ":#{a.label_id}" }.join(', ')
+ #attr['attrs'] = ", #{attr['attrs']}" unless attr['attrs'] == ''
+ #
+ #render_and_save attr
+ #
+ #children.each do |child|
+ # child.to_tk
+ #end
+
+ # p 111
+ # p self.attr_type
+ # p self.attr_name
+ #
+ # str = ''
+ #
+ # if parent.nil?
+ # str << <<RUBY
+ #class Application < TkRoot
+ #
+ #end
+ #RUBY
+ # else
+ #
+ # if attr_name
+ # str << "self.#{attr_name} = #{attr_type}.new(#{parent.attr_name}) \n"
+ # else
+ # str << "#{attr_type}.new(#{parent.attr_name}) \n"
+ # end
+ #
+ # end
+ #
+ # str << "\n" if children.size > 0
+ #
+ # children.each do |child|
+ # p 222
+ # p child.class
+ # str << child.to_tk
+ # end
+ #
+ # #puts str
+ #
+ # str
+ end
+end
+
+module Haml
+ module Parser
+ private
+ class ParseNode
+ include ParseNodeMethods
+ end
+ end
+end
5 lib/templates/application.liquid
@@ -0,0 +1,5 @@
+module Layout
+{% for method in methods %}
+{{ method }}
+{% endfor %}
+end
5 lib/templates/getter.liquid
@@ -0,0 +1,5 @@
+ def {{ name }}
+ return @{{ name }} if @{{ name }}
+
+ @{{ name }} = {{ type }}.new {{ parent }}
+ end
3  lib/templates/init_components.liquid
@@ -0,0 +1,3 @@
+ def init_components
+ {{ components }}
+ end
24 main.rb
@@ -0,0 +1,24 @@
+#require File.join(File.dirname(__FILE__), 'lib', 'haml')
+
+require 'bundler/setup'
+Bundler.require
+
+require './lib/haml/engine'
+require './lib/haml/parser'
+
+#require 'haml'
+
+haml_str = <<HAML
+#ruby_som
+ #setting_frame
+ %label#dsfs rows
+ %combobox#ad{:values => [1,2,3,4]}
+
+ #content_frame{:width => 31}
+HAML
+
+haml = Haml::Engine.new haml_str
+
+#puts haml.render
+puts haml.to_tk_module
+haml.render_tk_module
Please sign in to comment.
Something went wrong with that request. Please try again.