=============
Core commands
=============

The core commands wrap all standard KSS actions that are always available.
These do not contain any effects and focus mostly on DOM manipulation.

First we will need to create our command set.

  >>> from kss.base.corecommands import KSSCoreCommands
  >>> from kss.base import KSSCommands
  >>> from kss.base.coreselectors import css

  >>> commands = KSSCommands()
  >>> core = KSSCoreCommands(commands)

Now we will look at the individual methods provided by the core commands.

  >>> core.replaceInnerHTML(css('div'), 'some &lt;h1&gt;html&lt;/h1&gt;')
  >>> commands.render()
  '...replaceInnerHTML...<![CDATA[some &lt;h1&gt;html&lt;/h1&gt;]]>...'

-----------------
Node modification
-----------------

Set attribute
-------------

  >>> commands.clear()
  >>> core.setAttribute(css('div'), 'some name', 'some value')
  >>> print commands
  setAttribute(css('div'), name='some name', value='some value')

Set style
---------

You can use `setStyle` to change the look off an element.

  >>> commands.clear()
  >>> core.setStyle(css('div'), 'somename', 'some value')
  >>> print commands
  setStyle(css('div'), name='somename', value='some value')

It also has some validation so that you do not accidentily do an
unallowed thing.

  >>> core.setStyle(css('div'), 'some name', 'some value')
  Traceback (most recent call last):
  ...
  ValueError: Style properites cannot contain spaces


Add class
---------

  >>> commands.clear()
  >>> core.addClass(css('div'), 'somename')
  >>> print commands
  addClass(css('div'), value='somename')


Remove class
------------

  >>> commands.clear()
  >>> core.removeClass(css('div'), 'somename')
  >>> print commands
  removeClass(css('div'), value='somename')

Toggle class
------------

  >>> commands.clear()
  >>> core.toggleClass(css('div'), 'somename')
  >>> print commands
  toggleClass(css('div'), value='somename')


Focus
-----

  >>> commands.clear()
  >>> core.focus(css('div'))
  >>> print commands
  focus(css('div'))

----------------
HTML replacement
----------------

Replace inner HTML
------------------

  >>> commands.clear()
  >>> core.replaceInnerHTML(css('div'), 'some html')
  >>> print commands
  replaceInnerHTML(css('div'), html='some html')

You can also avoid KSS event setup. Use this only if you really need
the speedup because KSS will not be applied to these new nodes.

  >>> core.replaceInnerHTML(css('div'), 'some html', withKssSetup=False)
  >>> print commands
  replaceInnerHTML(css('div'), html='some html')
  replaceInnerHTML(css('div'), html='some html', withKssSetup='False')


Replace HTML
------------

  >>> commands.clear()
  >>> core.replaceHTML(css('div'), 'some html')
  >>> print commands
  replaceHTML(css('div'), html='some html')

You can also pass withKssSetup here (see replace inner HTML).

  >>> core.replaceHTML(css('div'), 'some html', withKssSetup=False)
  >>> print commands
  replaceHTML(css('div'), html='some html')
  replaceHTML(css('div'), html='some html', withKssSetup='False')


--------------
HTML insertion
--------------

Insert HTML before
------------------

  >>> commands.clear()
  >>> core.insertHTMLBefore(css('div'), 'some html')
  >>> print commands
  insertHTMLBefore(css('div'), html='some html')

Insert HTML after
-----------------

  >>> commands.clear()
  >>> core.insertHTMLAfter(css('div'), 'some html')
  >>> print commands
  insertHTMLAfter(css('div'), html='some html')

Insert HTML as first child
--------------------------

  >>> commands.clear()
  >>> core.insertHTMLAsFirstChild(css('div'), 'some html')
  >>> print commands
  insertHTMLAsFirstChild(css('div'), html='some html')

Insert HTML as last child
--------------------------

  >>> commands.clear()
  >>> core.insertHTMLAsLastChild(css('div'), 'some html')
  >>> print commands
  insertHTMLAsLastChild(css('div'), html='some html')


------------
Node removal
------------

Delete node
-----------

  >>> commands.clear()
  >>> core.deleteNode(css('div'))
  >>> print commands
  deleteNode(css('div'))

Delete node before
------------------

  >>> commands.clear()
  >>> core.deleteNodeBefore(css('div'))
  >>> print commands
  deleteNodeBefore(css('div'))

Delete node after
-----------------

  >>> commands.clear()
  >>> core.deleteNodeAfter(css('div'))
  >>> print commands
  deleteNodeAfter(css('div'))

Clear child nodes
-----------------

  >>> commands.clear()
  >>> core.clearChildNodes(css('div'))
  >>> print commands
  clearChildNodes(css('div'))

-------
Special
-------

Focus
-----

  >>> commands.clear()
  >>> core.focus(css('div'))
  >>> print commands
  focus(css('div'))


-------------
Copying nodes
-------------

Copy child nodes from
----------------------

  >>> commands.clear()
  >>> core.copyChildNodesFrom(css('div'), 'nodeid')
  >>> print commands
  copyChildNodesFrom(css('div'), html_id='nodeid')


Copy child nodes to
-------------------

  >>> commands.clear()
  >>> core.copyChildNodesTo(css('div'), 'nodeid')
  >>> print commands
  copyChildNodesTo(css('div'), html_id='nodeid')


------------
Moving nodes
------------

Move node before
----------------

  >>> commands.clear()
  >>> core.moveNodeBefore(css('div'), 'nodeid')
  >>> print commands
  moveNodeBefore(css('div'), html_id='nodeid')

Move node after
---------------

  >>> commands.clear()
  >>> core.moveNodeAfter(css('div'), 'nodeid')
  >>> print commands
  moveNodeAfter(css('div'), html_id='nodeid')


--------------
Global actions
--------------

Set client variable
-------------------

  >>> commands.clear()
  >>> core.setStateVar('varname', 'value')
  >>> print commands
  setStateVar(None, varname='varname', value='value')

Trigger event
-------------

  >>> commands.clear()
  >>> core.triggerEvent('eventname')
  >>> print commands
  triggerEvent(None, name='eventname')
