The easy way to code-golf ascii art! Task:

There are a lot of answers on this site that are arranged into ascii art, like this one. Usually the arrangement is done manually, but wouldn't a program help with that? :)

Your program will take 3 inputs:

The code, as one single line
The number of lines in the pattern (can be omitted if not necessary)
The pattern itself, as *s or another char

Rules:

You have to write a program (not a function) that reads from stdin
The text is placed left-to-right per line
If there is not enough text to fill the pattern, put .s in the remaining spaces
If there is too much text to fill the pattern, print it out after the output
code-golf, so the shortest code, in bytes wins

Sample Runs:
Input (Exact Fit test):
qwertyuiopasdfghjklzxcvbnm
4
***** * ***
*   * * *
*   * * *
***** * ***

Output:
qwert y uio
p   a s d
f   g h j
klzxc v bnm

Input (Extra characters test):
qwertyuiopasdfghjklzxcvbnm12345
4
***** * ***
*   * * *
*   * * *
***** * ***

Output:
qwert y uio
p   a s d
f   g h j
klzxc v bnm
12345

Input (Insufficient Characters test):
qwertyuiopasdfg
4
***** * ***
*   * * *
*   * * *
***** * ***

Output:
qwert y uio
p   a s d
f   g . .
..... . ...
Perl 6: 60 characters EDIT: 38 points (see bottom)

  #C#O     D#E#G#O       #L#
#F    #.#S#       T#A#C#K
  get\     .subst(       "*"
,{    shift       BEGIN [
  get\     .comb,\       "."
xx    * ]},       :g)\ .\
  say\     xx get\       ()\
#E    #X#C#       H#A#N#G
  #E#.     #C#O#M#       #!#


If you don't appreciate my terrible art skills, here's the golf:

get.subst("*",{shift BEGIN [get.comb,"."xx*]},:g).say xx get


This one does weird things with evaluation times.

First, the BEGIN keyword forces [get.comb, "." xx *] to be evaluated first, putting into an array the list of characters that make up "the code", followed by an infinite amount of "."s.

Next, the get at the end is evaluated, getting the number of lines of the ASCII art template. The xx operator repeats the first part of the program this many times. This makes more sense when you realize that code() xx count() is basically sugar for code() for 1..count(): count() should be evaluated first.

Finally, the get in the beginning of the program gets a line of the ASCII art template and substitutes every "*" with a value shifted off of the beginning of the array we made before everything else ({shift BEGIN …}).

EDIT:

Golfed down to 37 characters, plus one for the command line switch:

perl6 -pe's:g[\*]=shift BEGIN [get.comb,"."xx*]'


This is the same concept as the original, the -p switch iterating over each line (after the BEGIN has read in "the code"), and substituting all *s with the next letter from "the code" before printing it. The input format for this shouldn't include the number of lines of the format.