Skip to content
This repository was archived by the owner on Sep 30, 2018. It is now read-only.
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: opal/vienna
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: 50a413cd5876
Choose a base ref
...
head repository: opal/vienna
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 8f4a7984f9e0
Choose a head ref
  • 3 commits
  • 2 files changed
  • 2 contributors

Commits on Sep 20, 2014

  1. Copy the full SHA
    acdce63 View commit details

Commits on Sep 21, 2014

  1. changing tag_name and class_name implementation

    As per Adam instructions, class variable should be avoided at the
    moment, so making a new implementation method based
    lboutet85 committed Sep 21, 2014
    Copy the full SHA
    f2c4bee View commit details
  2. Merge pull request #22 from loicboutet/promote_tag_and_class_name_as_…

    …class_method
    
    Adding class method for view tag_name and class_name
    adambeynon committed Sep 21, 2014
    Copy the full SHA
    8f4a798 View commit details
Showing with 37 additions and 2 deletions.
  1. +11 −2 opal/vienna/view.rb
  2. +26 −0 spec/view_spec.rb
13 changes: 11 additions & 2 deletions opal/vienna/view.rb
Original file line number Diff line number Diff line change
@@ -4,6 +4,14 @@ def self.element(selector = nil)
selector ? @element = selector : @element
end

def self.tag_name(tag = nil)
define_method(:tag_name) { tag } if tag
end

def self.class_name(css_class = nil)
define_method(:class_name) { css_class } if css_class
end

def self.events
@events ||= []
end
@@ -31,7 +39,8 @@ def create_element
if el = self.class.element
scope.find el
else
scope.new tag_name
e = scope.new tag_name
e.add_class class_name
end
end

@@ -43,7 +52,7 @@ def class_name
end

def tag_name
:div
"div"
end

def find(selector)
26 changes: 26 additions & 0 deletions spec/view_spec.rb
Original file line number Diff line number Diff line change
@@ -31,6 +31,32 @@ def tag_name
klass.new.create_element.tag_name.should eq("table")
end

it "creates a new element with specified tag_name with the class method when no element defined" do
klass = Class.new(Vienna::View) do
tag_name 'table'
end

klass.new.create_element.tag_name.should eq("table")
end

it "creates a div element with specified class_name in class when no element defined" do
klass = Class.new(Vienna::View) do
def class_name
'my_class'
end
end

klass.new.create_element.class_name.should eq("my_class")
end

it "creates a div element with specified class_name with the class method when no element defined" do
klass = Class.new(Vienna::View) do
class_name 'my_class'
end
klass.new.create_element.class_name.should eq("my_class")
end


describe "with a parent view" do
it "returns an element found inside the scope of parent element" do
parent = Class.new(Vienna::View) { element "#parent-element" }.new