├── .rspec ├── lib ├── webface_haml.rb └── webface_haml │ └── parser.rb ├── Gemfile ├── spec ├── spec_helper.rb └── lib │ └── webface_haml │ └── webface_parser_spec.rb ├── webface_haml.gemspec ├── example.haml └── Gemfile.lock /.rspec: -------------------------------------------------------------------------------- 1 | --color 2 | -------------------------------------------------------------------------------- /lib/webface_haml.rb: -------------------------------------------------------------------------------- 1 | module WebfaceHaml;end 2 | 3 | require 'haml' 4 | require_relative 'webface_haml/parser' 5 | -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | gem "haml", git: "https://github.com/haml/haml" 4 | 5 | group :development do 6 | gem "bundler" 7 | gem "rspec" 8 | end 9 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require "rubygems" 2 | require "bundler/setup" 3 | require File.dirname(__FILE__) + "/../lib/webface_haml.rb" 4 | 5 | RSpec.configure do |config| 6 | end 7 | -------------------------------------------------------------------------------- /webface_haml.gemspec: -------------------------------------------------------------------------------- 1 | Gem::Specification.new do |s| 2 | s.name = "webface_haml" 3 | s.version = "0.0.1" 4 | s.date = "2017-04-11" 5 | s.summary = "A haml extension to generate Webface components" 6 | s.description = "A haml extension to generate Webface components" 7 | s.authors = ["Roman Snitko"] 8 | s.email = "roman.snitko@gmail.com" 9 | s.files = [ 10 | "lib/webface_haml.rb", 11 | "spec/webface_haml.rb", 12 | "spec/spec_helper.rb", 13 | "example.haml", 14 | "README", 15 | ".rspec", 16 | "Gemfile.lock", 17 | "Gemfile" 18 | ] 19 | s.homepage = "https://github.com/snitko/webface_haml" 20 | s.license = "MIT" 21 | end 22 | -------------------------------------------------------------------------------- /example.haml: -------------------------------------------------------------------------------- 1 | // General components syntax: 2 | %%component_name (role1,role2) (property1,property2) { attr_property_with_value: "value", attr_property_with_diff_name(name), attr_prop3(prop3): "value"} %tag_name 3 | // 4 | // For components, both formats of specifying names (snake_case an CamelCase) are acceptable: 5 | %%component_name 6 | %%ComponentName 7 | // or only set the ones we want: 8 | %%component_name(role1,role2){ property1: "value1" } 9 | // or 10 | %%component_name{ property2: "value2" } 11 | // 12 | // Sometimes we need to have a different html attribute name for the value 13 | %%component{ property1(prop1): 'value' } 14 | // 15 | // or the same without specifying value 16 | %%component{ property1(prop1) } 17 | // 18 | // parts syntax: 19 | %%:part_name 20 | %%:part_name%tag_name 21 | -------------------------------------------------------------------------------- /Gemfile.lock: -------------------------------------------------------------------------------- 1 | GIT 2 | remote: https://github.com/haml/haml 3 | revision: a8bb9e085fda7c8b41eacf96a7fcd5df9d845f6d 4 | specs: 5 | haml (5.0.4) 6 | temple (>= 0.8.0) 7 | tilt 8 | 9 | GEM 10 | remote: http://rubygems.org/ 11 | specs: 12 | diff-lcs (1.3) 13 | rspec (3.8.0) 14 | rspec-core (~> 3.8.0) 15 | rspec-expectations (~> 3.8.0) 16 | rspec-mocks (~> 3.8.0) 17 | rspec-core (3.8.0) 18 | rspec-support (~> 3.8.0) 19 | rspec-expectations (3.8.2) 20 | diff-lcs (>= 1.2.0, < 2.0) 21 | rspec-support (~> 3.8.0) 22 | rspec-mocks (3.8.0) 23 | diff-lcs (>= 1.2.0, < 2.0) 24 | rspec-support (~> 3.8.0) 25 | rspec-support (3.8.0) 26 | temple (0.8.0) 27 | tilt (2.0.9) 28 | 29 | PLATFORMS 30 | ruby 31 | 32 | DEPENDENCIES 33 | bundler 34 | haml! 35 | rspec 36 | 37 | BUNDLED WITH 38 | 1.16.1 39 | -------------------------------------------------------------------------------- /spec/lib/webface_haml/webface_parser_spec.rb: -------------------------------------------------------------------------------- 1 | require "spec_helper" 2 | 3 | describe WebfaceHaml::Parser do 4 | 5 | def render(text) 6 | Haml::Engine.new(text, parser_class: WebfaceHaml::Parser).render.rstrip 7 | end 8 | 9 | context "parser methods" do 10 | 11 | before(:each) do 12 | @parser = WebfaceHaml::Parser.new([]) 13 | end 14 | 15 | it "parses the component part of the haml line" do 16 | result = @parser.component_part_parsed("%%form_field(country_selector,selector)") 17 | expect(result).to eq({ class: "FormFieldComponent", roles: "country_selector,selector" }) 18 | end 19 | 20 | it "inserts roles into the component-related attributes in the original haml" do 21 | result = @parser.add_component_data_to_tag({ class: "FormFieldComponent", roles: "country_selector,selector" }, '%div(align="left")') 22 | expect(result).to eq('%div(align="left" data-component-class="FormFieldComponent" data-component-roles="country_selector,selector"){}') 23 | end 24 | 25 | it "inserts component attribute properties and their values into the component-related attributes in the original haml" do 26 | result = @parser.add_component_data_to_tag({ class: "FormFieldComponent", attribute_properties: 'hello: "world"'}, '%div(align="left")') 27 | expect(result).to eq('%div(align="left" data-component-class="FormFieldComponent" data-hello="world" data-component-attribute-properties="hello:data-hello"){}') 28 | end 29 | 30 | it "inserts component part attributes into the component-related attributes in the original haml" do 31 | result = @parser.add_component_data_to_tag({ part: "input_field" }, '%input') 32 | expect(result).to eq('%input(data-component-part="input_field"){}') 33 | end 34 | 35 | end 36 | 37 | it "adds component name as data attribute to the tag" do 38 | expect(render("%%DialogWindow%div hello")).to eq("